MSDN documentation -methods that have corresponding operators shouldn’t be called directly

In our old code I’vew noticed a few examples of code like the following:
 MyFortune = Decimal.Add(MyFortune, .01m);
I was wandered, why they didn’t use “+” sign, and didn’t find any explanation.
The MSDN reference documentation doesn’t explain, that methods like Add, Subtract,Multiply,Divide usually should not be called explicitely. 
Instead of using Add method it’s simpler to use + sign ( Addition Operator ).
E.g.
    MyFortune = Decimal.Add(MyFortune, .01m);
can be rewritten as 
    MyFortune += .01m;

Comment like this should be added to all methods, that have corresponding operators.

I’ve posted a suggestion to MS Feedback

Advertisements

DNN ability to ‘Publish Web Site’

3 years ago I’ve posted a workaround regarding DNN

BUG App_GlobalResources and ‘Publish Web Site’ in VS2005 
 
The issue is still not resolved and I recently received an email

I would like to thank you a lot for your post on a DNN forum which explain how to use DNN in precompiled mode.

( AppGlobalRessources…… )

T H A N K S !!!!!!!!!!

 I am glad that the workaround is still useful, but DNN team should create a new version(even with breaking changes)

Scheduled Tasks tool should validate username/password combination

Schedule Tasks in Windows  required to specify username and password. However it doesn’t verify that the combination is correct.

Scheduled Tasks tool should have an option to verify username/password combination and this validation should be forced when user saved(clicked OK) the task.

I’ve noticed the issue on Windows 2003 server. Not sure, is it implemented on newer windows versions.

Do not check-in DEBUG specific code.

We are using .Net Remoting to interact beteeen client and back end server. I needed to call a method from services class.
For debugging purposes I decided to create the class directly. It was easier to debug without starting extra back-end process.
The code was like the following:

IMyServices services = (IMyServices)RemotingHelper.GetObject(typeof(IMyServices));
#if DEBUG
    services = new MyServices();
#endif
// Process the task
services.ProcessItems(ItemsCollection); 

During the development I checked that the method done the required processing and changed the parameter object as expected.

And I’ve checked in the code, assuming that in Release mode the application will work the same way just by instantiating proxy instead of full object.
However in Release mode changes in parameter inside calling method were not returned back.
Of course, If parameter is serializable, it is passed by value. and correct implementation will use return value

 ItemsCollection = services.ProcessItems(ItemsCollection);

But more general recommendation before check-in remove/comment-out any DEBUG specific shortcuts and test the code  as it will be in production.

Call eventTimer_Elapsed method asyncronoulsy OnStart of Windows Service

We have   eventTimer in Windows Service  (similar as described in  Timer Objects in Windows Services with C#.NET 
and Using Timers in a Windows Service) to run the  relatively long-running process repeatedly.
 
NOTE: It is NOT a good idea to Use a Windows Service just to run a scheduled process, but I have to maintain a legacy application, that was written as a Windows Service .
 
The process called each time when eventTimer_Elapsed. But I want to run it immediately(not to wait until timer will elapsed)  when service started or Continued.
However I wanted to call it asynchronously from OnStart method, because otherwise Start command seems to hang until process is finished.
Thanks to asyncronous calls for delegates, I ‘ve created a function to invoke eventTimer_Elapsed from any place asyncronously and my service has the following methods:
 
private void BeginInvokeElapsedEvent(object sender, ElapsedEventArgs e)
{// Initialize the first update asynchronously
ElapsedEventHandler dlgt = eventTimer_Elapsed;

dlgt.BeginInvoke(sender,e);

}
protected override void OnContinue() 
{
 this.eventTimer.Start();
BeginInvokeElapsedEvent(this,null);// MyLongProcess();
base.OnContinue ();

}

protected override void OnStart(string[] args)
{

Initialise();

// Initialize the first update asynchronously// MyLongProcess();
BeginInvokeElapsedEvent(this,null);

}

private void eventTimer_Elapsed(object sender, ElapsedEventArgs e)
{

MyLongProcess();

}

Related links:Comparing the Timer Classes in the .NET Framework Class Library