J
Jim
I just inherited a .NET 1.1 GUI and upgraded to .NET 2.0. Naturally, there
are several errors indicating that a control was accessed in a thread that
is not the main thread. I have been fixing these errors all over the place,
and there is plenty of documentation on the Internet explaining this error
....
http://msdn2.microsoft.com/en-us/library/ms171728.aspx
Anyway, while I have fixed several of these issues, one has proven to be a
little more difficult. The code basically looks like this ...
public class X
{
private static System.Windows.Forms.StatusBarPanel panel = null;
....
public static StatusBarPanel TheStatusBar
{
set
{
panel = value;
}
}
public static void SetPanelText(string theText)
{
if(null != panel)
{
// This is where the thread access exception occurs
panel.Text = theText;
}
}
}
I have tried the normal method of creating a delegate and setting a callback
function. However, the static panel control does not have an Invoke
function. I have tried calling panel.Parent.Invoke(...), but this does not
do anything either.
After this didn't work for me, I tried creating a background worker like it
says to do in the link I reference earlier. The code for my
RunWorkerCompleted function basically looked like this ...
{
if (null != panel)
{
// mText was set earlier in the SetPanelTextFunction. Later, in the
SetPanelText function,
// I call the RunWorkerAsync to reach this code in the
RunWorkerCompleted function.
panel.Text = mText;
}
}
Anyway, this didn't work for me either. I get the same cross thread
exception. (The BackgroundWorker is created when the panel value is set).
All in all, does anybody know how I can Invoke this control since the
control has been declared as static? I can't take away the static
declaration either without breaking about 15 projects in the solution that
seem to use this control.
Thanks,
-- Jim
are several errors indicating that a control was accessed in a thread that
is not the main thread. I have been fixing these errors all over the place,
and there is plenty of documentation on the Internet explaining this error
....
http://msdn2.microsoft.com/en-us/library/ms171728.aspx
Anyway, while I have fixed several of these issues, one has proven to be a
little more difficult. The code basically looks like this ...
public class X
{
private static System.Windows.Forms.StatusBarPanel panel = null;
....
public static StatusBarPanel TheStatusBar
{
set
{
panel = value;
}
}
public static void SetPanelText(string theText)
{
if(null != panel)
{
// This is where the thread access exception occurs
panel.Text = theText;
}
}
}
I have tried the normal method of creating a delegate and setting a callback
function. However, the static panel control does not have an Invoke
function. I have tried calling panel.Parent.Invoke(...), but this does not
do anything either.
After this didn't work for me, I tried creating a background worker like it
says to do in the link I reference earlier. The code for my
RunWorkerCompleted function basically looked like this ...
{
if (null != panel)
{
// mText was set earlier in the SetPanelTextFunction. Later, in the
SetPanelText function,
// I call the RunWorkerAsync to reach this code in the
RunWorkerCompleted function.
panel.Text = mText;
}
}
Anyway, this didn't work for me either. I get the same cross thread
exception. (The BackgroundWorker is created when the panel value is set).
All in all, does anybody know how I can Invoke this control since the
control has been declared as static? I can't take away the static
declaration either without breaking about 15 projects in the solution that
seem to use this control.
Thanks,
-- Jim