BeginInvoke in C#

Looks to be same as async, meaning that the delegate passed to BeginInvoke will be called async and the result can be awaited by calling EndInvoke.
EndInvoke will block until the return value can be retrieved.
The parameters of EndInvoke include the out and ref parameters ( ByRef and ByRef in Visual Basic) of the method that you want to execute asynchronously, plus the IAsyncResult returned by BeginInvoke.
BeginInvoke returns an IAsyncResult, which can be used to monitor the progress of the asynchronous call.
BeginInvoke is the Asynchronous version of Invoke. Asynchronous means the thread will not block the caller as opposed to a synchronous call which is blocking.

Eg. See:

BeginInvoke vs task in C#

Task.Run to create a task, followed by ContinueWith to attach a continuation task. This continuation task will log any exception that was thrown from the parent task. Also, use TaskContinuationOptions.OnlyOnFaulted to make sure the continuation only runs if an exception occurred.

IAsyncResult, is significantly older, and much less powerful. Task was introduced in .NET 4, and is the preferred way of representing asynchronous operations now. It’s much simpler to use, particularly in C# 5 which supports “asynchronous functions” where you can await a task (or other asynchronous operation) in a non-blocking way.

Using a Task instead of calling BeginInvoke probably won’t change much about how the operation itself is executed (although it gives you more options in terms of scheduling etc), but it makes a huge difference from the perspective of the code which wants to “watch” the operation, use the results, wait for multiple tasks, handle failures etc.

If you can possibly use C# 5 (either with .NET 4.5, or with .NET 4 plus the async targeting pack) it will make your life considerably easier when it comes to managing asynchronous operations. It’s the way forward 🙂

Resolving Kerberos Auth Issues in Windows

I have a kerberized svc that is being called from an Asp.Net WebAPI.

Here’s the code:

HttpClient client = new HttpClient();
HttpResponseMessage response = await client.GetAsync(“link”);
if (response.IsSuccessStatusCode)
dynamic res = response.Content.ReadAsStringAsync();
Log.Info(“Response from server {1} is: {2}”, url.Host, res.ToString());
Log.Error(“Response from server {1} is not successful. Setting LoggingStatus as False”, url.Host);

Also tried kilst to check kerberos tokens and the “Windows Credentials Manager” to reset the credentials…no luck


Starting with the .NET Framework version 2.0, the common language runtime allows most unhandled exceptions in threads to proceed naturally. In most cases this means that the unhandled exception causes the application to terminate.

In our case, the logs show that the thread is getting terminated, but the application isn’t.

Getting wierd performance counter corrupt error in exe

I have a clickOnce packaged windows forms app, which is not using any perf counters, and on one user machine, giving this error on startup (form_load):

System.InvalidOperationException: Cannot load Counter Name data because an invalid index ” was read from the registry.
at System.Diagnostics.PerformanceCounterLib.GetStringTable(Boolean isHelp)
at System.Diagnostics.PerformanceCounterLib.get_NameTable()
at System.Diagnostics.PerformanceCounterLib.get_CategoryTable()
at System.Diagnostics.PerformanceCounterLib.CategoryExists(String machine, String category)
at System.Diagnostics.PerformanceCounterCategory.Exists(String categoryName, String machineName)
at System.Workflow.Runtime.PerformanceCounterManager.SetInstanceName(String instanceName)
at System.Workflow.Runtime.WorkflowRuntime.StartRuntime()
at System.Workflow.Runtime.WorkflowRuntime.InternalCreateWorkflow(CreationContext context, Guid instanceId)
at System.Workflow.Runtime.WorkflowRuntime.CreateWorkflow(Type workflowType, Dictionary`2 namedArgumentValues, Guid instanceId)…my class where i initiate the workflow

Finally found this KB Article:
It says:

“Lodctr /r”

Run cmd as admin for it to work…

Note that this error was coming only for a particular user on the machine, indicating that it’s related to the user profile..ANother user on this machine was not getting this error

WiFi issues

Suddenly today my android phone stopped connecting to connectify with the error: Obtaining IP Address and getting stuck there….

I recalled that yesterday, i had used the windows new adhoc network to share my LAN Connection.

Turns out, this made my Avast to change the network profile from private to public….

Anyways, once i changed it today, all is working fine now…

But, in the process i learnt a few things:

1. Wireless adaptor has to be turned on 

2. You don’t have to turn on network sharing of local area connection adaptor for your net to be shared over wifi

3. Window’s setup wireless ad-hoc n/w does not work with android…but other windows machines only

4. Connectify3 was much better than connectify 9, as with 9, it stops after 30 min of use, unless you buy the damn thing

5. mHotspot is much better and free