本文整理汇总了C#中System.Threading.Thread类的典型用法代码示例。如果您正苦于以下问题:C# System.Threading.Thread类的具体用法?C# System.Threading.Thread怎么用?C# System.Threading.Thread使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
System.Threading.Thread类属于命名空间,在下文中一共展示了System.Threading.Thread类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: BUT_connect_Click
private void BUT_connect_Click(object sender, EventArgs e)
{
if (comPort.IsOpen)
{
threadrun = false;
comPort.Close();
BUT_connect.Text = Strings.Connect;
}
else
{
try
{
comPort.PortName = CMB_serialport.Text;
}
catch { CustomMessageBox.Show(Strings.InvalidPortName); return; }
try {
comPort.BaudRate = int.Parse(CMB_baudrate.Text);
} catch {CustomMessageBox.Show(Strings.InvalidBaudRate); return;}
try {
comPort.Open();
} catch {CustomMessageBox.Show("Error Connecting\nif using com0com please rename the ports to COM??"); return;}
t12 = new System.Threading.Thread(new System.Threading.ThreadStart(mainloop))
{
IsBackground = true,
Name = "Nmea output"
};
t12.Start();
}
}
示例3: 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();
}
示例4: Start
public void Start(Action run)
{
Debug.Assert(!isRunning);
thread = new System.Threading.Thread(new System.Threading.ThreadStart(run));
thread.Start();
}
示例5: 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;
}
示例6: 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();
}
}
示例7: watch
public watch()
{
t = new System.Threading.Thread(new System.Threading.ThreadStart(loop));
s = new udpstate();
s.e = new IPEndPoint(IPAddress.IPv6Any, 9887);
s.u = new UdpClient(s.e);
}
示例8: webclient
public webclient(Stream netstream, string path)
{
Path = path;
clientStream = netstream;
System.Threading.Thread mythread = new System.Threading.Thread(new System.Threading.ThreadStart(thetar));
mythread.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: Run
public void Run()
{
if ((Site == null) || (Site.ID < 1))
{
return;
}
if ((MailTo == "") || (Subject == "") || (Body == ""))
{
new Log("System").Write("Send Email: MailTo, Subject or Body parameters error.");
return;
}
EmailServer_From = Site.SiteOptions["Opt_EmailServer_From"].Value.ToString();
EmailServer_EmailServer = Site.SiteOptions["Opt_EmailServer_EmailServer"].Value.ToString();
EmailServer_User = Site.SiteOptions["Opt_EmailServer_UserName"].Value.ToString();
EmailServer_Password = Site.SiteOptions["Opt_EmailServer_Password"].Value.ToString();
if ((EmailServer_From == "") || (EmailServer_EmailServer == "") || (EmailServer_User == ""))
{
new Log("System").Write("Send Email: Read EmailServer configure fail.");
return;
}
lock (this) // 确保临界区被一个 Thread 所占用
{
thread = new System.Threading.Thread(new System.Threading.ThreadStart(Do));
thread.IsBackground = true;
thread.Start();
}
}
示例11: 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.");
}
}
示例12: 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();
}
示例13: 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++;
}
}
示例14: 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();
}
示例15: startPreview
private void startPreview()
{
#region Create capture object if it is not already created
if (_capture == null)
{
try
{
_capture = new Capture();
}
catch (NullReferenceException excpt)
{
MessageBox.Show(excpt.Message);
}
}
#endregion
#region Start the capture process and display in the preview window
if (_capture != null)
{
//start the capture
//Application.Idle += ProcessFrame;
captureEnabled = true;
System.Threading.Thread capThread = new System.Threading.Thread(new System.Threading.ThreadStart(captureThread));
capThread.Start();
}
#endregion
}