Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Thursday, February 08, 2007

ParameterizedThreadStart

ParameterizedThreadStart is to pass parameter to new starting Thread.

you can pass only one parameter of type object. the function definition should have one in param of type object.

Passing Parameter to Thread


In .NET 2.0, there is a new delegate, ParameterizedThreadStart, which takes
a parameter of type object. You can create a thread using an instance of
this delegate instead of just ThreadStart, and a new overload to Thread.Start
allows you to specify the value to be passed to the new thread. This is simple, but only accepts
a single parameter and isn't type-safe (just like the options when using thread pool threads).
The earlier code could then be rewritten as:



[In some method or other]

Thread t = new Thread (new ParameterizedThreadStart(FetchUrl));

t.Start (myUrl);



[And the actual method...]

static void FetchUrl(object url)

{

// use url here, probably casting it to a known type before use

}



http://www.yoda.arachsys.com/csharp/threads/parameters.shtml





powered by performancing firefox

Thursday, February 01, 2007

Debugging Windows Service

#if (DEBUG)

Service service = new Service();

service.Start(); //define a public method: public void Start(){OnStart(null);}
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);

#endif

Deserialize to Object from XML Config File in .NET 2.0

static EventLogConfig GetEventLogConfig {

get {

XmlSerializer mySerializer = new XmlSerializer(typeof(EventLogConfig));

XmlNodeReader reader = new XmlNodeReader(Settings.Default.EventLogConfig.DocumentElement);



return (EventLogConfig) mySerializer.Deserialize(reader);



}

}






powered by performancing firefox

Modify application settings in .NET 2.0

(Settings1.Settings) you can't change application settings in code. You can only change user
settings. To change the application settings, you need to write your
own code to open the configuration file as any xml file and modify it

http://blogs.msdn.com/mohamed_sharafs_blog/archive/2006/12/12/using-application-user-settings-in-c-2-0.aspx