threading with events
-
this question especially for Sacha Barber because I learn threading from his article (Beginners Guide To Threading In .NET Part 2 of n). First Question : how to end / exit thread? From tutorial and MSDN help, I assume that thread is end when the thread function ends. Is this true ? Before 2nd question, this is my code on worker thread:
public event ReportConversion ReportConversionDone;
...
private void RutinKonversi(object fListobj)
{
...
OnStatusReport(pd); //raising event
}
protected void OnStatusReport(ProggressDoneEventArgs e)
{
if (ReportConversionDone != null)
{
ReportConversionDone(this, e);
}
}This is my code on UI thread for handling thread event:
void conv_ReportConversionDone(object sender, ProggressDoneEventArgs e)
{
//marshal to UI thread
if (sender == conv)
{
context.Post(new SendOrPostCallback(delegate(object gakPenting)
{//inline code or anonymous method
#region code event handler cross thread
switch (e.ItemToReport)
{
...
}
#endregion
}), null);
}
}When I try passing data from background thread to UI, By putting breakpoints, I know if the thread is executed once. When I start worker thread for the first time (when application just started), event handler on UI is executed once. But when I start for third times, event handler is executed three times too. My 2nd question is : how to make event handler just executed once whenever worker thread is done. This is the screenshot : first time[^] third time I pressed extract[^]
No one can prevent me to learn something
-
this question especially for Sacha Barber because I learn threading from his article (Beginners Guide To Threading In .NET Part 2 of n). First Question : how to end / exit thread? From tutorial and MSDN help, I assume that thread is end when the thread function ends. Is this true ? Before 2nd question, this is my code on worker thread:
public event ReportConversion ReportConversionDone;
...
private void RutinKonversi(object fListobj)
{
...
OnStatusReport(pd); //raising event
}
protected void OnStatusReport(ProggressDoneEventArgs e)
{
if (ReportConversionDone != null)
{
ReportConversionDone(this, e);
}
}This is my code on UI thread for handling thread event:
void conv_ReportConversionDone(object sender, ProggressDoneEventArgs e)
{
//marshal to UI thread
if (sender == conv)
{
context.Post(new SendOrPostCallback(delegate(object gakPenting)
{//inline code or anonymous method
#region code event handler cross thread
switch (e.ItemToReport)
{
...
}
#endregion
}), null);
}
}When I try passing data from background thread to UI, By putting breakpoints, I know if the thread is executed once. When I start worker thread for the first time (when application just started), event handler on UI is executed once. But when I start for third times, event handler is executed three times too. My 2nd question is : how to make event handler just executed once whenever worker thread is done. This is the screenshot : first time[^] third time I pressed extract[^]
No one can prevent me to learn something
Sounds like the code to start the thread is broken. And if you have a question for an article author, ask in the forum under the article.
Christian Graus Driven to the arms of OSX by Vista.
-
this question especially for Sacha Barber because I learn threading from his article (Beginners Guide To Threading In .NET Part 2 of n). First Question : how to end / exit thread? From tutorial and MSDN help, I assume that thread is end when the thread function ends. Is this true ? Before 2nd question, this is my code on worker thread:
public event ReportConversion ReportConversionDone;
...
private void RutinKonversi(object fListobj)
{
...
OnStatusReport(pd); //raising event
}
protected void OnStatusReport(ProggressDoneEventArgs e)
{
if (ReportConversionDone != null)
{
ReportConversionDone(this, e);
}
}This is my code on UI thread for handling thread event:
void conv_ReportConversionDone(object sender, ProggressDoneEventArgs e)
{
//marshal to UI thread
if (sender == conv)
{
context.Post(new SendOrPostCallback(delegate(object gakPenting)
{//inline code or anonymous method
#region code event handler cross thread
switch (e.ItemToReport)
{
...
}
#endregion
}), null);
}
}When I try passing data from background thread to UI, By putting breakpoints, I know if the thread is executed once. When I start worker thread for the first time (when application just started), event handler on UI is executed once. But when I start for third times, event handler is executed three times too. My 2nd question is : how to make event handler just executed once whenever worker thread is done. This is the screenshot : first time[^] third time I pressed extract[^]
No one can prevent me to learn something
asugix wrote:
this question especially for Sacha Barber because I learn threading from his article (Beginners Guide To Threading In .NET Part 2 of n).
Then this is the wrong place. Article has a discussion board and author will get a notification when new messages are posted.
asugix wrote:
First Question : how to end / exit thread? From tutorial and MSDN help, I assume that thread is end when the thread function ends. Is this true ?
YES.
asugix wrote:
how to make event handler just executed once whenever worker thread is done. This is the screenshot :
You are not showing enough code to answer this.
Navaneeth How to use google | Ask smart questions
-
Sounds like the code to start the thread is broken. And if you have a question for an article author, ask in the forum under the article.
Christian Graus Driven to the arms of OSX by Vista.