本文整理汇总了C#中System.Threading.Thread.Start方法的典型用法代码示例。如果您正苦于以下问题:C# System.Threading.Thread.Start方法的具体用法?C# System.Threading.Thread.Start怎么用?C# System.Threading.Thread.Start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.Thread
的用法示例。
在下文中一共展示了System.Threading.Thread.Start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MainForm
public MainForm()
{
InitializeComponent();
try
{
foreach (IPAddress ip in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
{
if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
localIP = ip;
break;
}
}
udpListen = new UDPListen(new IPEndPoint(localIP, localPort));
System.Threading.ThreadStart threadStartListen;
threadStartListen = new System.Threading.ThreadStart(udpListen.open);
udpListen.msgReceiptEvent += new msgReceiptHandler(listen_msgReceiptEvent);
threadListen = new System.Threading.Thread(threadStartListen);
threadListen.Start();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
示例2: Start
public void Start(Action run)
{
Debug.Assert(!isRunning);
thread = new System.Threading.Thread(new System.Threading.ThreadStart(run));
thread.Start();
}
示例3: button1_Click
private void button1_Click(object sender, EventArgs e)
{
try
{
System.Threading.ThreadStart ts = delegate
{
CLKsFATXLib.Streams.Reader OR = Original.Reader();
CLKsFATXLib.Streams.Writer D = Destination.Writer();
OR.BaseStream.Position = 0;
D.BaseStream.Position = 0;
for (long i = 0; i < Original.Length; i += 0x6000)
{
D.Write(OR.ReadBytes(0x6000));
progressBar1.Invoke((MethodInvoker)delegate
{
try
{
progressBar1.Maximum = (int)(Original.Length >> 4);
progressBar1.Value = (int)(((i >> 8) < 0) ? 0 : i >> 4);
}
catch { }
});
}
OR.Close();
D.Close();
};
System.Threading.Thread t = new System.Threading.Thread(ts);
t.Start();
}
catch (Exception x) { MessageBox.Show(x.Message); }
}
示例4: runUpload
public static void runUpload( )
{
if (Properties.Settings.Default.firstrun)
return;
NameValueCollection postdata = new NameValueCollection();
postdata.Add("u", Properties.Settings.Default.username);
postdata.Add("p", Properties.Settings.Default.password);
if (!Clipboard.ContainsImage() && !Clipboard.ContainsText()) {
nscrot.balloonText("No image or URL in clipboard!", 2);
return;
}
if (!Clipboard.ContainsText()) {
Image scrt = Clipboard.GetImage();
System.Threading.Thread upld = new System.Threading.Thread(( ) =>
{
nscrot.uploadScreenshot(postdata, scrt);
});
upld.SetApartmentState(System.Threading.ApartmentState.STA);
upld.Start();
} else {
string lURL = Clipboard.GetText();
System.Threading.Thread shrt = new System.Threading.Thread(( ) =>
{
nscrot.shorten(lURL);
});
shrt.SetApartmentState(System.Threading.ApartmentState.STA);
shrt.Start();
}
}
示例5: StartHostAndClient_SimpleSyncMethodSyncCallWithAsync_Success
public async void StartHostAndClient_SimpleSyncMethodSyncCallWithAsync_Success()
{
bool @continue = false;
var thread = new System.Threading.Thread(() =>
{
using (var host = new WcfExampleServiceHost("localhost:10000"))
{
host.Start();
@continue = true;
while (@continue)
{
System.Threading.Thread.Sleep(10);
}
host.Close();
}
});
thread.Start();
while ([email protected])
{
System.Threading.Thread.Sleep(10);
}
var client = new WcfExampleServiceAsyncClient("localhost:10000");
SimpleSyncMethodResponseModel responseSimpleSyncMethod = client.SimpleSyncMethod(new SimpleSyncMethodRequestModel { Message = "Hello World" });
Assert.IsNotNull(responseSimpleSyncMethod);
Assert.AreEqual("SimpleSyncMethod: Hello World", responseSimpleSyncMethod.Message);
@continue = false;
thread.Join();
}
示例6: Start
public void Start(string portName, int baudRate, Parity parity, int dataBits, StopBits stopBits)
{
if (!GetAvailablePorts().Contains(portName))
{
throw new Exception(string.Format("Unknown serial port: {0}", portName));
}
// Start the timer to empty the receive buffer (in case data smaller than MAX_RECEIVE_BUFFER is received)
_bufferTimer = new Timer();
_bufferTimer.Interval = BUFFER_TIMER_INTERVAL;
_bufferTimer.Elapsed += _bufferTimer_Elapsed;
_bufferTimer.Start();
// Instantiate new serial port communication
_serialPort = new SerialPort(portName, baudRate, parity, dataBits, stopBits);
// Open serial port communication
_serialPort.Open();
// Check that it is actually open
if (!_serialPort.IsOpen)
{
throw new Exception(string.Format("Could not open serial port: {0}", portName));
}
_serialPort.ReadTimeout = 100; // Milliseconds
_readThread = new System.Threading.Thread(ReadThread);
_readThreadRunning = true;
_readThread.Start();
}
示例7: DiscoverDynamicCategories
public override int DiscoverDynamicCategories()
{
_thread = new System.Threading.Thread(new System.Threading.ThreadStart(ReadEPG));
_thread.Start();
Settings.Categories.Clear();
RssLink cat = null;
cat = new RssLink()
{
Name = "Channels",
Other = "channels",
Thumb = "http://arenavision.in/sites/default/files/FAVICON_AV2015.png",
HasSubCategories = false
};
Settings.Categories.Add(cat);
cat = new RssLink()
{
Name = "Agenda",
Other = "agenda",
Thumb = "http://arenavision.in/sites/default/files/FAVICON_AV2015.png",
HasSubCategories = false
};
Settings.Categories.Add(cat);
Settings.DynamicCategoriesDiscovered = true;
return Settings.Categories.Count;
}
示例8: Run
public void Run()
{
//if ((ElectronTicket_HPCQ_Getway == "") || (ElectronTicket_HPCQ_UserName == "") || (ElectronTicket_HPCQ_UserPassword == ""))
//{
// log.Write("ElectronTicket_XGCQ Task 参数配置不完整.");
// return;
//}
// 已经启动
if (State == 1)
{
return;
}
lock (this) // 确保临界区被一个 Thread 所占用
{
State = 1;
gCount1 = 0;
thread = new System.Threading.Thread(new System.Threading.ThreadStart(Do));
thread.IsBackground = true;
thread.Start();
log.Write("ElectronTicket_XGCQ Task Start.");
}
}
示例9: Ajouter_Click
private void Ajouter_Click(object sender, EventArgs e)
{
System.Threading.Thread monthread = new System.Threading.Thread(new System.Threading.ThreadStart(Ajout));
monthread.Start();
this.Close();
LoadPerso();
}
示例10: ActionWindowLoaded
private async void ActionWindowLoaded(object sender, RoutedEventArgs e)
{
if (count == 0)
{
id = Properties.Settings.Default.UserID;
//ClientNameTextBox.Text = id;
Active = true;
Thread = new System.Threading.Thread(() =>
{
Connection = new HubConnection(Host);
Proxy = Connection.CreateHubProxy("SignalRMainHub");
Proxy.On<string, string>("addmessage", (name, message) => OnSendData(DateTime.Now.ToShortTimeString()+" ["+ name + "]\t " + message));
Proxy.On("heartbeat", () => OnSendData("Recieved heartbeat <3"));
Proxy.On<HelloModel>("sendHelloObject", hello => OnSendData("Recieved sendHelloObject " + hello.Molly + " " + hello.Age));
Connection.Start();
while (Active)
{
System.Threading.Thread.Sleep(10);
}
}) { IsBackground = true };
Thread.Start();
count++;
}
}
示例11: SendNonQuery
protected void SendNonQuery(string stmt)
{
var pts = new System.Threading.ParameterizedThreadStart(_SendNonQuery);
System.Threading.Thread t = new System.Threading.Thread(pts);
t.Start(stmt);
t.Join();
}
示例12: reConnect
public void reConnect()
{
clientSocket.Close();
clientSocket = null;
sendBuffer = new byte[1024];//Send buffer //c# automatic assigesd to 0
try
{
clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
System.Threading.Thread tt = new System.Threading.Thread(delegate()
{
try
{
clientSocket.Connect(ip, port);
}
catch (Exception ee)
{
//MessageBox.Show(ee.Message + "\r\n From:" + this);
}
});
tt.Start();
}
catch (Exception e)
{
//MessageBox.Show(e.Message + "\r\n From:" + this);
}
}
示例13: socket
public byte[] sendBuffer = null;//Send buffer
public socket(String ipAddress)
{
ip = ipAddress;
sendBuffer = new byte[1024];//Send buffer //c# automatic assigesd to 0
try
{
//创建一个Socket
clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
System.Threading.Thread tt = new System.Threading.Thread(delegate()
{
//连接到指定服务器的指定端口
//方法参考:http://msdn.microsoft.com/zh-cn/library/system.net.sockets.socket.connect.aspx
try
{
clientSocket.Connect(ip, port);
}
catch(Exception ee)
{
MessageBox.Show(ee.Message);
}
});
tt.Start();
}
catch (Exception e)
{
MessageBox.Show(e.Message + "\r\n From:" + this);
}
}
示例14: MainWindow
public MainWindow()
{
InitializeComponent();
this.IsPostPanelExpand = true;
this.IsFunctionPanelExpand = true;
this.IsMessagePostPanelExpand = true;
this.AuthPanel.OkButton.Click += new RoutedEventHandler(OkButton_Click);
this.AuthPanel.PrevButton.Click += new RoutedEventHandler(PrevButton_Click);
this.AuthPanel.NextButton.Click += new RoutedEventHandler(NextButton_Click);
this.ReplyPanel.ReplyButton.Click += new RoutedEventHandler(ReplyPanelReplyButton_Click);
this.ReplyPanel.CancelButton.Click += new RoutedEventHandler(ReplyPanelCancelButton_Click);
#region Task Tray
int ScreenWidth = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
int Screenheigth = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;
int AppWidth = (int)this.Width;
int AppHeight = (int)this.Height;
Canvas.SetLeft(this, ScreenWidth - AppWidth); //ScreenWidth / 2 - AppWidth / 2;
Canvas.SetTop(this, Screenheigth - AppHeight); //Screenheigth / 2 - AppHeight / 2;
this.StateChanged += new EventHandler(MainWindow_StateChanged);
this.taskIcon = new System.Windows.Forms.NotifyIcon();
this.taskIcon.Visible = true;
this.taskIcon.Icon = Properties.Resources.YammyyIcon;
this.taskIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(taskIcon_MouseClick);
this.taskIcon.ContextMenu = new System.Windows.Forms.ContextMenu();
System.Windows.Forms.MenuItem item = new System.Windows.Forms.MenuItem("&Exit", taskIconItemExit_Click);
this.taskIcon.ContextMenu.MenuItems.Add(item);
#endregion
System.Threading.Thread th = new System.Threading.Thread(new System.Threading.ThreadStart(InitialCheck));
th.Start();
}
示例15: EventNotifyClient
public EventNotifyClient(string strIP,int port,bool bAutoRetry)
{
this.bAutoRetry = bAutoRetry;
this.port = port;
string[]ips=strIP.Split(new char[]{'.'});
for(int i=0;i<4;i++)
ipByte[i]=System.Convert.ToByte(ips[i]);
//if (bAutoRetry)
//{
System.Threading.Thread th = new System.Threading.Thread(Connect_Task);
th.Start();
//}
//else
//{
// tcp = new System.Net.Sockets.TcpClient();
// tcp.Connect(new System.Net.IPAddress(ipByte), port);
// bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
// connected = true;
// Console.WriteLine("NotifySerevr connected!");
// new System.Threading.Thread(ClientWork).Start();
//}
}