G
Guest
Hello,
i´m using the backgroundworker in an Consolenapplication. For testing i
write the current ManagedThreadid from Main, the Backgroundworker
Dowork-delegate and RunworkerCOmpleted-delegate. i expected that the ids from
Main and RunworkerCompleted are the saim - but they are not!
can anyone help? here is the coding:
class Program
{
static BackgroundWorker bw = new BackgroundWorker();
static void Main(string[] args)
{
// On my machine thread id 10
Console.WriteLine("Main started. Thread id = " +
Thread.CurrentThread.ManagedThreadId.ToString());
bw.DoWork += new DoWorkEventHandler(bw_DoWork);
bw.RunWorkerCompleted += new
RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
bw.RunWorkerAsync();
Console.WriteLine("Press return");
Console.ReadLine();
}
static void bw_RunWorkerCompleted(object sender,
RunWorkerCompletedEventArgs e)
{
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// On my machine thread id is 11 not 10, which is unexpected
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Console.WriteLine("Completed. Thread id = " +
Thread.CurrentThread.ManagedThreadId.ToString());
}
static void bw_DoWork(object sender, DoWorkEventArgs e)
{
// On my machine thread id is 7 not 10, which is expected
Console.WriteLine("Background thread started. Thread id = " +
Thread.CurrentThread.ManagedThreadId.ToString());
}
}
best regards
Volkhard
i´m using the backgroundworker in an Consolenapplication. For testing i
write the current ManagedThreadid from Main, the Backgroundworker
Dowork-delegate and RunworkerCOmpleted-delegate. i expected that the ids from
Main and RunworkerCompleted are the saim - but they are not!
can anyone help? here is the coding:
class Program
{
static BackgroundWorker bw = new BackgroundWorker();
static void Main(string[] args)
{
// On my machine thread id 10
Console.WriteLine("Main started. Thread id = " +
Thread.CurrentThread.ManagedThreadId.ToString());
bw.DoWork += new DoWorkEventHandler(bw_DoWork);
bw.RunWorkerCompleted += new
RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
bw.RunWorkerAsync();
Console.WriteLine("Press return");
Console.ReadLine();
}
static void bw_RunWorkerCompleted(object sender,
RunWorkerCompletedEventArgs e)
{
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// On my machine thread id is 11 not 10, which is unexpected
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Console.WriteLine("Completed. Thread id = " +
Thread.CurrentThread.ManagedThreadId.ToString());
}
static void bw_DoWork(object sender, DoWorkEventArgs e)
{
// On my machine thread id is 7 not 10, which is expected
Console.WriteLine("Background thread started. Thread id = " +
Thread.CurrentThread.ManagedThreadId.ToString());
}
}
best regards
Volkhard