I am working on a DirectX based simulator. On which I have to check for a device whether device has been plugged-in or removed from the PC.
I've managed to make classes for device arrival and removal on another thread, which raises an event from the thread itself on device arrival or removal. The corresponding event method is being called in the main form and there:
Assume Form1
is main window and Form2
is the secondary.
Form2 form2Instance = new Form2();
I want to show another Form (Form2
) keeping main Window (Form1
) in behind (same as it behaves as form2Instance.ShowDialog();
in general cases.)
After a few tries I have done it by
Applicatin.Run(new Form2());
, but the Form2 doesn't behave as'form2Instance.ShowDialog();
in any way.
Just giving the code if it can help in answering:
iARMdetectionThreadClass detection;
InProgram_iARMdetection iARMStatusGUI;
private void Form2_Load(object sender, EventArgs e)
{
iARMStatusGUI = new InProgram_iARMdetection();
detection = new iARMdetectionThreadClass();
detection.IniARM_device_Arrive += new iARMdetectionThreadClass.iARM_device_ArrivedEventHandler(detection_IniARM_device_Arrive);
detection.IniARM_device_Remove += new iARMdetectionThreadClass.iARM_device_RemovedEventHandler(detection_IniARM_device_Remove);
detection.startThread();
}
void detection_IniARM_device_Remove(iARM_deviceInfo senderInfo)
{
detection.StopCheckBeingRemoved();
MethodInvoker act = delegate
{
this.label_iARMStatus.Text = detection.iARM_deviceInf.iARMStatus;
};
this.label_iARMStatus.BeginInvoke(act);
Application.Run(new InProgram_iARMdetection()); //Blocking code
detection.StartCheckBeingRemoved();
}
void detection_IniARM_device_Arrive(iARM_deviceInfo senderInfo)
{
MethodInvoker act = delegate
{
this.label_iARMStatus.Text = detection.iARM_deviceInf.iARMStatus;
};
this.label_iARMStatus.BeginInvoke(act);
//detection.StopCheckArriving();
//detection.StartCheckArriving();
}
I need the code to be Blocking Code. In here:
Application.Run(new InProgram_iARMdetection()); //Blocking code