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);
refParam++;
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.BeginInvoke((ThreadStart)delegate()
{
this.richTextBox1.AppendText("Worker updated UI.\n");
});
}
}).Start();
}

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.

http://www.ineta.org/DesktopDefault.aspx?tabindex=10&tabid=61

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
  ErrorCode=-2147417850
  Message="Retrieving the COM class factory for component with CLSID {3FA7DEB3-6438-101B-ACC1-00AA00423326} failed due to the following error: 80010106."
  Source="TSCGContactSearch"
  StackTrace:
       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
http://blogs.msdn.com/stephen_griffin/archive/2004/09/24/233985.aspx

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.

HKEY_CLASSES_ROOT\CLSID\{3FA7DEB3-6438-101B-ACC1-00AA00423326}\InprocServer32\ThreadingModel

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


 

ASP.NET 1.1 Application Service Unavailable Error AGAIN

This is driving me crazy. Fortunately this time I located error more easily.
Looking at error logs gave me direction about. Error message was:

It is not possible to run two different versions of ASP.NET in the same IIS process. Please use the IIS Administration Tool to reconfigure your server to run the application in a separate process.

so everything was fine when I created new Application pool for sites using .NET 1.1 and another for .NET 2.0 sites and problem was fixed

[TOOLS]Some Great .NET and VisualStudio.NET Tools

James Avery has produced a couple of "short lists" of tools that are very, very helpful to .NET developers.  Have a look at them.  Actually, don't wast time - just go ahead right now and download the ones that will save you tons of time in your daily work:
Got from: http://weblogs.asp.net/jtobler/archive/2005/12/05/432407.aspx

ASP.NET 1.1 Application Service Unavailable Error

We've found a terrible problem while developing websites with ASP.NET 1.1. Initially I though it is version  problem because I have .NET Framework 2.0 installed on development machine.

I found an forum post where they said everything is fine when ASPNET account is in Administrators group. But this is nonsense - ASPNET  accout CANNOT BE IN ADMINISTRATORS group. Otherwise this will be BIG security hole.

So I kept looking for solution and found article on MS Knowledge base - Process and request identity in ASP.NET:

Blindly grating rights described in section Default permissions for the ASPNET account didn't help us a lot.
I did the following.

  1. Delete ASPNET account from development machine.
  2. Execute from Visual Studio .NET 2003 Command Prompt  aspnet_regiis -i so ASPNET 1.1 is installed on system and ASPNET accoutn is created.
  3. Grant read rights for ASPNET on %sysroot%\Windows
  4. Grant full rights for ASPNET on %installroot%\ASP.NET Temporary Files
  5. Grant read rights for ASPNET on IIS Web project folder so ASPNET can read root web.config file
  6. Grant read rights for ASPNET on virtual folder where project reside
  7. Execute iisreset from command prompt.

This resolve the problem. I hope this helps.