Click here to Skip to main content
15,897,518 members
Home / Discussions / C#
   

C#

 
QuestionInternet Explorer frames errors Pin
David Bicknell12-Nov-05 10:15
David Bicknell12-Nov-05 10:15 
Questionproblem to set AllowDrop from callback Pin
xjsun12-Nov-05 10:03
xjsun12-Nov-05 10:03 
AnswerRe: problem to set AllowDrop from callback Pin
Leslie Sanford12-Nov-05 10:23
Leslie Sanford12-Nov-05 10:23 
GeneralRe: problem to set AllowDrop from callback Pin
xjsun12-Nov-05 11:39
xjsun12-Nov-05 11:39 
GeneralRe: problem to set AllowDrop from callback Pin
Leslie Sanford12-Nov-05 12:32
Leslie Sanford12-Nov-05 12:32 
GeneralRe: problem to set AllowDrop from callback Pin
S. Senthil Kumar13-Nov-05 4:42
S. Senthil Kumar13-Nov-05 4:42 
GeneralRe: problem to set AllowDrop from callback Pin
xjsun13-Nov-05 7:30
xjsun13-Nov-05 7:30 
GeneralRe: problem to set AllowDrop from callback Pin
Leslie Sanford13-Nov-05 9:24
Leslie Sanford13-Nov-05 9:24 
Whenever you need to update a control or form from another thread, you have to use the control's or form's Invoke or BeginInvoke methods. Say you have an event handler in your form that gets notified from another thread. To make it thread safe, it might look something like this:

private void SomeEventHandler(object sender, EventArgs e)
{
    if(InvokeRequired)
    {
        EventHandler handler = new EventHandler(UpdateControl);
                
        Invoke(handler, new object[] { e });
    }
    else
    {
        UpdateControl(sender, e);
    }
}

private void UpdateControl(object sender, EventArgs e)
{
    someLabel.Text = "Some event occurred.";
}


Applying this to your callback, you would check the InvokeRequired property in the callback, and if it is true, you would use the form's Invoke or BeginInvoke to invoke a delegate on the same thread as the GUI in order to modify the form's control. I really don't know of any other way of doing this. That's why your comment about reading some articles that showed a different way threw me off.

I don't think you have to worry about blocking the GUI very much here. True the callback will eventually get handled on the same thread as the GUI, but for simply setting a control property, it shouldn't take any noticable time at all. Hope this helps.
GeneralRe: problem to set AllowDrop from callback Pin
xjsun13-Nov-05 19:45
xjsun13-Nov-05 19:45 
QuestionWhy the output is like this ? Pin
Kamrul Hasan12-Nov-05 9:14
Kamrul Hasan12-Nov-05 9:14 
AnswerRe: Why the output is like this ? Pin
Joshua Quick12-Nov-05 10:04
Joshua Quick12-Nov-05 10:04 
GeneralRe: Why the output is like this ? Pin
Kamrul Hasan12-Nov-05 22:33
Kamrul Hasan12-Nov-05 22:33 
GeneralRe: Why the output is like this ? Pin
Joshua Quick12-Nov-05 23:00
Joshua Quick12-Nov-05 23:00 
GeneralRe: Why the output is like this ? Pin
S. Senthil Kumar13-Nov-05 4:55
S. Senthil Kumar13-Nov-05 4:55 
GeneralRe: Why the output is like this ? Pin
Joshua Quick13-Nov-05 10:02
Joshua Quick13-Nov-05 10:02 
QuestionGrouping Radio Buttons Pin
Kamrul Hasan12-Nov-05 8:33
Kamrul Hasan12-Nov-05 8:33 
AnswerRe: Grouping Radio Buttons Pin
Joshua Quick12-Nov-05 10:09
Joshua Quick12-Nov-05 10:09 
AnswerRe: Grouping Radio Buttons Pin
da vinci coder13-Nov-05 12:03
da vinci coder13-Nov-05 12:03 
QuestionReadOnly Radio Button? Pin
rich_wenger12-Nov-05 8:25
rich_wenger12-Nov-05 8:25 
AnswerRe: ReadOnly Radio Button? Pin
Colin Angus Mackay12-Nov-05 8:28
Colin Angus Mackay12-Nov-05 8:28 
GeneralRe: ReadOnly Radio Button? Pin
rich_wenger12-Nov-05 12:03
rich_wenger12-Nov-05 12:03 
GeneralRe: ReadOnly Radio Button? Pin
Kamrul Hasan12-Nov-05 22:42
Kamrul Hasan12-Nov-05 22:42 
GeneralRe: ReadOnly Radio Button? Pin
rich_wenger13-Nov-05 3:13
rich_wenger13-Nov-05 3:13 
GeneralRe: ReadOnly Radio Button? Pin
Dan Neely14-Nov-05 2:10
Dan Neely14-Nov-05 2:10 
GeneralRe: ReadOnly Radio Button? Pin
rich_wenger14-Nov-05 4:50
rich_wenger14-Nov-05 4:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.