T
Tom C
I'm creating a Form in my component and setting it's parent to another
application mains window via ShowDialog(IWin32Window). If I set the
process name to say "Notepad" it works fine, and behaves as expected.
If I set the process name to my main application and do not run it
under VS 2005 is also works properly. Only when I'm debugging the
application does it throw the "Cross-thread operation not valid:
Control accessed from a thread other than the thread it was created
on."
I'm creating the showing the dialog from the same thread, so I don't
see why this error is occuring.
Thread uiThread2 = new Thread(UIThreadProc);
uiThread2.IsBackground = false;
uiThread2.Start(mySession);
private void UIThreadProc(Object mySession)
{
CheckAccountInfo oCheckingInfo = new CheckAccountInfo(mySession);
System.Diagnostics.Process[] procs =
System.Diagnostics.Process.GetProcessesByName("SomeApplication");
if (procs.Length != 0)
{
IntPtr hwnd = procs[0].MainWindowHandle;
// This line causes the mentioned exception while
running in the debugger
Result = oCheckingInfo.ShowDialog(new
WindowWrapper(hwnd));
}
}
public class WindowWrapper : System.Windows.Forms.IWin32Window
{
/// <summary>
///
/// </summary>
/// <param name="handle"></param>
public WindowWrapper(IntPtr handle)
{
_hwnd = handle;
}
public IntPtr Handle
{
get { return _hwnd; }
}
private IntPtr _hwnd;
}
application mains window via ShowDialog(IWin32Window). If I set the
process name to say "Notepad" it works fine, and behaves as expected.
If I set the process name to my main application and do not run it
under VS 2005 is also works properly. Only when I'm debugging the
application does it throw the "Cross-thread operation not valid:
Control accessed from a thread other than the thread it was created
on."
I'm creating the showing the dialog from the same thread, so I don't
see why this error is occuring.
Thread uiThread2 = new Thread(UIThreadProc);
uiThread2.IsBackground = false;
uiThread2.Start(mySession);
private void UIThreadProc(Object mySession)
{
CheckAccountInfo oCheckingInfo = new CheckAccountInfo(mySession);
System.Diagnostics.Process[] procs =
System.Diagnostics.Process.GetProcessesByName("SomeApplication");
if (procs.Length != 0)
{
IntPtr hwnd = procs[0].MainWindowHandle;
// This line causes the mentioned exception while
running in the debugger
Result = oCheckingInfo.ShowDialog(new
WindowWrapper(hwnd));
}
}
public class WindowWrapper : System.Windows.Forms.IWin32Window
{
/// <summary>
///
/// </summary>
/// <param name="handle"></param>
public WindowWrapper(IntPtr handle)
{
_hwnd = handle;
}
public IntPtr Handle
{
get { return _hwnd; }
}
private IntPtr _hwnd;
}