Galin Iliev's blog

Software Architecture & Development

C# 2.0 Anonymous methods can accept arguments

Wow! I just came across the great artile on CodeProject about C# Anonymous methods and guess what I learned - Anonymous methods can accept arguments. I did not know about this feature and I think I am going to use it a lot.

As shown in the following example, an anonymous method can accept arguments of any type. You can also use the keywords ref and out to tune how arguments are passed to the method:

class Program {
delegate int DelegateType( int valTypeParam, string refTypeParam,
ref int refParam, out int outParam);
static DelegateType GetMethod() {
return delegate( int valTypeParam , string refTypeParam,
ref int refParam , out int outParam ) {
System.Console.WriteLine( "Hello valParam:{0} refTypeParam:{1}",
valTypeParam, refTypeParam);
outParam = 9;
return valTypeParam;
}; // End of the body of the anonymous method.
static void Main() {
DelegateType delegateInstance = GetMethod();
int refVar = 5;
int outVar;
int i = delegateInstance( 1, "one", ref refVar, out outVar );
int j = delegateInstance( 2, "two", ref refVar, out outVar );
System.Console.WriteLine( "i:{0} j:{1} refVar:{2} outVar:{3}",
i, j, refVar, outVar);

For more information see C#2 Anonymous Methods

NenoLoje Wrote Seriously

NenoLoje wrote:

Seriously, there a lots of applications that implement their own user & role administration and permission concept.

What many of them do not know is there is a ready-to-use-solution - called Authorization Manager (short: AzMan) - by Microsoft that allows you to provide Role-Based Access and Control of your applications and providing a greater degree of flexibility to the IT staff running it.

Don't reinvent the wheel every time - especially in the case of security / identity / authentication - systems!

Thanks Neno, This is great info

Elegant update winform controls from child thread

I've just came across this interesting solution to update winform controls from child thread

private void button17_Click(object sender, EventArgs e)
// Create and start Worker Thread using anonymous delegate.

new Thread((ThreadStart)delegate()
for (int i = 0; i < 5; i++)
//this.richTextBox1.AppendText("Cross-thread operation will not work.");

// Update UI on the UI thread using another anonymous delegate.
this.richTextBox1.AppendText("Worker updated UI.\n");

Many thanks to William Stacey [MVP]

Live from Redmond

INETA Live! is a series brought to you primarily by user group leaders around the country that have exceptional material they believe would be good to share with other user group leaders. Don't miss these if you are interested in growing your own user group.

Live from Redmond! is a series presented to you directly by Microsoft product teams! No marketing hype -- just the technical details that you want to hear and need to know. Ask questions directly to product team members! Stay ahead of your peers by attending these exclusive sessions.

Difficult Mapi.Sesstion initialization

I had hard couple days in resolving an issue related with initialization of MAPI session in child thread from .NET application. I tried bunch of situations but the result was same:
I got the error saying me that CDO cannot me initialized.

System.Runtime.InteropServices.COMException was caught
  Message="Retrieving the COM class factory for component with CLSID {3FA7DEB3-6438-101B-ACC1-00AA00423326} failed due to the following error: 80010106."
       at TSCGContactSearch.OutlookSearch.fGetOutlookSession(Object& olretNameSpace, Object& olretApp, Session& cdoretMapiSession) in D:\Projects\SCS\dotNet\ContactSearch\TSCGContactSearch\OutlookSearch.vb:line 614

I read in forums but still .. nothing...
I found this article form Stephen Griffin

I tried to call MAPIInitialization from child thred .. but still I get this anoying error.

Finally I came accross an article on MSDN in italian that gave me the idea to change ThreadingModel key in registry (under MAPI.Session's GUID) from "Both" to "Appartment" and ... here we go. No more errors. My application runs.


this was strange error as application was fine when was compiled under .NET 1.1 but .NET 2.0 breaks it. Very strange...


First results from .NET 2.0 certification exams

First results from .NET 2.0 certification exams are out. They say I passed the following exams:

071-548: PRO: Designing and Developing Microsoft® Windows®-Based Applications by Using the Microsoft .NET Framework
071-549: PRO: Designing and Developing Enterprise Applications by Using the Microsoft® .NET Framework

I am expecting results from UPGRADE exams: 071-554 and 071-553