public static void ThreadFunc()
{
while (true)
{
System.Threading.Thread.Sleep(10 * 1000);
WorkFlowWS.Service rws = new WorkFlowWS.Service();
string msg = rws.GetReminder(108);
if (msg != "")
{
//打开一个窗体
}
}
}这是一个Windows服务中的线程,我想在 msg != "" 时打开一个窗体,该如何实现呢,谢谢!
{
while (true)
{
System.Threading.Thread.Sleep(10 * 1000);
WorkFlowWS.Service rws = new WorkFlowWS.Service();
string msg = rws.GetReminder(108);
if (msg != "")
{
//打开一个窗体
}
}
}这是一个Windows服务中的线程,我想在 msg != "" 时打开一个窗体,该如何实现呢,谢谢!
psi.FileName = "SimpleCopy.exe";//注上你要打开的EXE名称
Process p = new Process();
p.StartInfo = psi;
p.Start();试试它看行不行:)
是進程的話,就用樓上那位仁兄的方法。
要是線程就用如下方法:
先引用System.Windows.Forms
using System.windows.Forms;
if (msg != "")
{
Form temp = new Form();
MethodInvoke mi = new MethodInvoke( temp.Show );
this.Invoke( mi );
}
{
Form temp = new Form();
MethodInvoke mi = new MethodInvoke( temp.Show );
this.Invoke( mi );
}
{
Form temp = new Form();
MyInvokemi = new MyInvoke( temp.Show );
this.BeginInvoke( mi );
}
///调用的方法
all_alose d = new all_alose(allClose);
this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, d); ///定义的委托
delegate void all_alose();
/// <summary>
/// 窗体变换[实际工作的方法]
/// </summary>
void allClose()
{
AccessibilityClient ac = new AccessibilityClient();
ac.Show(); this.Close();
}
{
delegate void ShowForm(); private UserMessageForm _userMessage;
private MainForm _currentForm;
public ShowUserMessageForm(MainForm currentForm,UserMessage userMessageForm)
{
this._currentForm = currentForm;
this._userMessage = userMessage;
}
public void Show()
{
Thread t = new Thread(new ThreadStart(show));
t.Start();
}
private void show()
{
if(this.currentForm != null && _userMessage != null)
this._currentForm.Invoke(new ShowForm(showForm));
}
private void showForm()
{
userMessageForm.Show();
}
} 这样用:
ShowUserMessageForm sum = new ShowUserMessageForm (this, yourWantShowForm);
sum.Show();
{
userMessageForm.Show();
}改一下,
private void showForm()
{
Application.Run(userMessageForm);
}