C#: What threads are custom controls running in

13 October 2009

Here’s a useful (well maybe) block of code to determine what thread controls are running in.

Note that this code was placed in a base class (hence the 1s on the stack frame to show callers etc).

protected override void CreateChildControls()
{
  var stack = new StackTrace();
  var message = string.Format(
    CultureInfo.InvariantCulture,
    "THREAD ID: {0}, CLASSNAME: {1}, METHOD: {2}",
    Thread.CurrentThread.ManagedThreadId,
    stack.GetFrame(1).GetMethod().ReflectedType.FullName,
    stack.GetFrame(1).GetMethod().Name);
  Debug.WriteLine(message);
}



permalink   (currently 0 comments)

Add A Comment

Your Name:
* Please enter the code: Captcha Image
   

* Please enter your message: