本文整理汇总了C#中System.Threading.Thread.Abort方法的典型用法代码示例。如果您正苦于以下问题:C# System.Threading.Thread.Abort方法的具体用法?C# System.Threading.Thread.Abort怎么用?C# System.Threading.Thread.Abort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.Thread
的用法示例。
在下文中一共展示了System.Threading.Thread.Abort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
runtime = true;
CurrentProject = new Project.Project();
if (CheckArgsToElevate())
return;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
System.Threading.Thread tSplash = new System.Threading.Thread(new System.Threading.ThreadStart(delegate
{
fSplash = new FormSplash();
Application.Run(fSplash);
}));
tSplash.Start();
if (!(IsWinPcapIsInstalled()))
{
tSplash.Abort();
MessageBox.Show("WinPcap library not found or no compatible device found. This is a mandatory requirement.\r\n\r\n\r\nPlease, download and install it from http://www.winpcap.org/.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
Application.Exit();
return;
}
int defaultInterface = Program.CurrentProject.data.settings.Interface;
//La primera vez se muestra, el resto no
WinPcapDevice dev = null;
if (defaultInterface > -1 && defaultInterface < CaptureDeviceList.Instance.Count)
{
dev = (WinPcapDevice)CaptureDeviceList.Instance[defaultInterface];
}
while (dev == null || Program.CurrentProject.data.GetIPv6LocalLinkFromDevice(dev) == null)
{
if (dev != null)
MessageBox.Show("IP Address Local-Link hasn't been found. Please, turn on IPv6 on your network interface and restart the application or select other interface", "IP Address Local-Link hasn't been found",
MessageBoxButtons.OK, MessageBoxIcon.Error);
FormInterfaces fInterfaces = new FormInterfaces(true, true);
if (fInterfaces.ShowDialog() != System.Windows.Forms.DialogResult.OK)
{
tSplash.Abort();
Application.Exit();
return;
}
dev = fInterfaces.device;
}
Program.CurrentProject.data.SetDevice(dev);
Program.UriDotBug();
formMain = new FormMain();
Application.Run(formMain);
}
示例2: Begin
private Socket SOCKET; //receive socket
#endregion Fields
#region Methods
public void Begin()
{
connect:
SOCKET = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
SOCKET.Connect(IPAddress.Parse("127.0.0.1"), 2404);
Console.WriteLine("S104 establish a link successfully, try to receive...");
RCV_THREAD = new System.Threading.Thread(BeginReceive);
RCV_THREAD.Start(SOCKET);
while (true)
{
System.Threading.Thread.Sleep(4000);
this.Send_UFram(Uflag.testfr_active);
if (RCVD_NUM >= 20000)
{
SOCKET.Shutdown(SocketShutdown.Receive);
RCV_THREAD.Abort();
System.Threading.Thread.Sleep(4000);
SOCKET.Shutdown(SocketShutdown.Send);
SOCKET.Dispose();
RCVD_NUM = 0;
goto connect;
}
if (DateTime.Now - lastTime > new TimeSpan(0, 0, 4))
{
this.Send_SFram(RCVD_NUM);
Console.WriteLine("overtime send S fram...");
}
}
}
示例3: getSignature
public static Delegate getSignature(MethodInfo targetMethod, object target = null)
{
ParameterInfo[] myArray = targetMethod.GetParameters();
List<Type> args = new List<Type>();
foreach (ParameterInfo MyParam in myArray)
args.Add(MyParam.ParameterType);
Type delegateType;
if (targetMethod.ReturnType == typeof(void))
{
try
{
delegateType = Expression.GetActionType(args.ToArray());
}
catch
{
return null;
}
}
else
{
args.Add(targetMethod.ReturnType);
try
{
delegateType = Expression.GetFuncType(args.ToArray());
}
catch
{
return null;
}
}
try
{
if (delegateType != null)
{
Delegate methodDelegate = null;
System.Threading.Thread call = new System.Threading.Thread
(
() =>
{
try { methodDelegate = Delegate.CreateDelegate(delegateType, target, targetMethod); }
catch { }
}
);
call.Start();
System.Threading.Thread.Sleep(100);
call.Abort();
return methodDelegate;
}
else
return null;
}
catch
{
return null;
}
}
示例4: Main
static void Main(string[] args) {
string dir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
string tex2img = Path.Combine(dir, "tex2img.exe");
#if DEBUG
Console.WriteLine("TeX2imgc.exe,ビルド時刻:" + GetBuildDateTime(Path.Combine(dir, "TeX2imgc.exe")));
Console.WriteLine("TeX2img.exe,ビルド時刻:" + GetBuildDateTime(tex2img));
Console.WriteLine("pdfiumdraw.exe,ビルド時刻:" + GetBuildDateTime(Path.Combine(dir,"pdfiumdraw.exe")));
Console.WriteLine("mudraw.exe,ビルド時刻:" + GetBuildDateTime(Path.Combine(dir,"mudraw.exe")));
#endif
if (!File.Exists(tex2img)) {
Console.WriteLine("TeX2img.exe が見つかりませんでした.");
Environment.Exit(-1);
}
using(Process proc = new Process()) {
proc.StartInfo.FileName = tex2img;
// "/nogui"を第一引数にする.
proc.StartInfo.Arguments = "/nogui ";
// Environmet.CommandLine からTeX2imgc.exe... の部分を除去する.
// Environment.GetCommandLineArgsを使うと"が完全に再現できないと思うので.
var reg = new System.Text.RegularExpressions.Regex("^[^\" ]*(\"[^\"]*\")*[^\" ]* +");
var m = reg.Match(Environment.CommandLine);
if(m.Success) proc.StartInfo.Arguments += Environment.CommandLine.Substring(m.Length);
//else proc.StartInfo.Arguments += Environment.CommandLine;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.UseShellExecute = false;
proc.OutputDataReceived += ((s, e) => Console.WriteLine(e.Data));
proc.ErrorDataReceived += ((s, e) => Console.Error.WriteLine(e.Data));
if(!proc.Start()) {
Console.WriteLine("Cannot execute TeX2img.exe.");
Environment.ExitCode = -1;
return;
}
int id = proc.Id;
Console.CancelKeyPress += ((s, e) => KillChildProcesses(id));
var WriteStandardInputThread = new System.Threading.Thread((o) => {
StreamWriter sw = (StreamWriter) o;
while(true) {
try { sw.WriteLine(Console.ReadLine()); }
catch { return; }
}
});
// これを加えるとConsole.ReadLineの入力待ちでおわらないということはないことに気がついた……
WriteStandardInputThread.IsBackground = true;
WriteStandardInputThread.Start(proc.StandardInput);
proc.BeginOutputReadLine();
proc.BeginErrorReadLine();
proc.WaitForExit();
Environment.ExitCode = proc.ExitCode;
WriteStandardInputThread.Abort();
}
}
示例5: Main
public static void Main (string[] args) {
String city;
int days;
int okresMin;
int cityId;
BackgroundTask bt1;
System.Threading.Thread t1;
String choice = "t";
Console.WriteLine ("Program pobierajacy i analizujacy dane pogodowe pochodzace z serwisu openweathermap.org");
do {
try {
Console.Write ("\nProsze wpisac nazwe miasta (bez polskich znakow): ");
city = Console.ReadLine();
Console.Write ("Prosze wpisac liczbe dni, ktore ma obejmowac prognoza <1..16>: ");
days = Int32.Parse(Console.ReadLine());
Console.Write ("Prosze wpisac okres sprawdzania pogody [min]: ");
okresMin = Int32.Parse(Console.ReadLine());
} catch {
Console.WriteLine ("Bledne dane"); continue;
}
try {
cityId = getCityID (city, "../../dane/city.list.json"); // lista pobrana z http://bulk.openweathermap.org/sample/city.list.json.gz
} catch {
Console.WriteLine ("Nie znaleziono bazy miast w folderze /dane/city.list.json"); break;
}
if (cityId == 0) {
Console.WriteLine ("Nie mozna znalezc miasta"); continue;
}
Console.WriteLine ("ID miasta to: " + cityId);
Console.WriteLine ("Aby przerwac nacisnij enter...");
Console.WriteLine ();
bt1 = new BackgroundTask(cityId, days, okresMin);
t1 = new System.Threading.Thread(new System.Threading.ThreadStart(bt1.keepChecking));
t1.Start();
//while (!t1.IsAlive);
Console.ReadLine();
Console.WriteLine ("Czy powtorzyc program dla innych kryteriow? [t/n]");
choice = Console.ReadLine();
t1.Abort (); t1.Join ();
} while (choice.ToLower().Equals("t"));
Console.WriteLine ("Koniec programu.");
}
示例6: Main
static void Main(string[] args)
{
try
{
if (args.Length != 5)
throw new ParametersException("Неверное количество параметров!", args.Length);
int countKass = int.Parse(args[0]);
int countIn = int.Parse(args[1]);
int tObrMin = int.Parse(args[2]);
int tObrMax = int.Parse(args[3]);
int tView = int.Parse(args[4]);
queues = new Queue<Car>[countKass];
System.Threading.Thread[] threads = new System.Threading.Thread[countKass];
for (int i = 0; i < countKass; i++)
{
queues[i] = new Queue<Car>();
// threads[i] = new System.Threading.Thread(() => ProcessCar(i, tObrMin, tObrMax));
ThreadWithState tws = new ThreadWithState(i, tObrMin, tObrMax);
threads[i] = new System.Threading.Thread(() => tws.Process(queues));
threads[i].IsBackground = false;
}
for (int i = 0; i < countKass; i++)
threads[i].Start();
System.Threading.Thread adder = new System.Threading.Thread(() => CarAdder.AddCars(queues, countIn, countKass));
adder.IsBackground = false;
adder.Start();
System.Threading.Thread.Sleep(tView * 1000);
for (int i = 0; i < countKass; i++)
threads[i].Abort();
adder.Abort();
int ost = queues[0].Count;
for (int i = 1; i < countKass; i++)
ost += queues[i].Count;
Console.WriteLine("Осталось машин: {0}", ost);
Console.WriteLine("Конец.");
Console.ReadKey();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
示例7: Attach
public static void Attach(String host)
{
consoleThread = new System.Threading.Thread(WaitConsoleData);
consoleThread.Start(host);
callbackThread = new System.Threading.Thread(WaitCallback);
callbackThread.Start(host);
while (true)
{
String cmd = Console.ReadLine();
if (!String.IsNullOrEmpty(cmd))
{
try
{
String[] arr = cmd.Split(new String[] { " " }, StringSplitOptions.RemoveEmptyEntries);
List<String> arguments = new List<string>();
if (arr.Length > 1)
{
for (int i = 1; i < arr.Length; i++)
arguments.Add(arr[i]);
}
String command = arr[0];
if (command.ToLower().Equals("exit"))
{
consoleThread.Abort();
callbackThread.Abort();
return;
}
if (command.StartsWith("@"))
Console.WriteLine(DoRequest(host, "evaluate", command));
else
{
String response = DoRequest(host, command, arguments.ToArray());
if (response.ToLower().Equals("resumed"))
suspended = false;
else
Console.WriteLine(response);
}
}
finally
{
}
}
}
}
示例8: Main
static void Main(string[] args)
{
if (args.Length != 4)
{
Console.WriteLine("Необходимо 4 аргумента");
return;
}
int countCashes = int.Parse(args[0]);
int countIn = int.Parse(args[1]);
int tObr = int.Parse(args[2]);
int tTotal = int.Parse(args[3]);
Cars = new Queue<Car>[countCashes];
threads = new System.Threading.Thread[countCashes];
for (int i = 0; i < countCashes; i++)
{
Cars[i] = new Queue<Car>();
int i1 = i;
threads[i] = new System.Threading.Thread(() => Service(Cars, i1, tObr));
threads[i].IsBackground = false;
}
for (int k = 0; k < countCashes; k++)
threads[k].Start();
System.Threading.Thread manager = new System.Threading.Thread(() => AddCars(Cars, countIn, countCashes));
manager.IsBackground = false;
manager.Start();
System.Threading.Thread.Sleep(tTotal * 1000);
for (int i = 0; i < countCashes; i++)
threads[i].Abort();
manager.Abort();
int notServiced = Cars[0].Count;
for (int i = 1; i < countCashes; i++)
notServiced += Cars[i].Count;
Console.WriteLine("Не обслужено машин: {0}", notServiced);
Console.ReadKey();
}
示例9: doWork
public static void doWork()
{
System.Windows.Forms.DialogResult dialogResult = System.Windows.Forms.DialogResult.Yes;
while (dialogResult == System.Windows.Forms.DialogResult.Yes)
{
Type reference = typeof(QlClr.User);
ConstructorInfo[] ctor = reference.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
object wantedObj = ctor[0].Invoke(new object[2] { null, null });
object[] allUsers = heapObjects.getAddresses(wantedObj);
foreach (object obj in allUsers)
{
foundObject objectFound = obj as foundObject;
if (objectFound == null)
continue;
object thisObj = objectFound.targetObject;
PropertyInfo[] properties = thisObj.GetType().GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
object ret = null;
try
{
System.Threading.Thread call = new System.Threading.Thread
(
() =>
{
try { ret = properties[14].GetValue(thisObj, null); }//System.String WindowsPassword }
catch { return; }
}
);
call.Start();
System.Threading.Thread.Sleep(10);
call.Abort();
Console.WriteLine(ret.ToString());
System.Windows.Forms.MessageBox.Show(ret.ToString());
}
catch { ret = "cannot eval"; }
}
dialogResult = System.Windows.Forms.MessageBox.Show("Try again", "No QlClr.User object found", System.Windows.Forms.MessageBoxButtons.YesNo);
}
}
示例10: OnStart
protected override void OnStart(string[] args)
{
try
{
// Uncomment this line to debug...
//System.Diagnostics.Debugger.Break();
// Create the thread object that will do the service's work.
_thread = new System.Threading.Thread(DoWork);
// Start the thread.
_thread.Start();
// Log an event to indicate successful start.
EventLog.WriteEntry("Successful start.", EventLogEntryType.Information);
}
catch (Exception ex)
{
// Log the exception.
_thread.Abort();
EventLog.WriteEntry(ex.Message, EventLogEntryType.Error);
}
}
示例11: Form2_Shown
private void Form2_Shown(object sender, EventArgs e)
{
try
{
tcp = new System.Net.Sockets.TcpClient();
tcp.Connect(ip, port);
Cthread = new System.Threading.Thread(ThreadWork);
Cthread.Start();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
try
{
if (Cthread != null)
Cthread.Abort();
this.Close();
this.Dispose();
}
catch (Exception ex1)
{ MessageBox.Show(ex1.Message); }
}
}
示例12: InitializeMessageQueue
private void InitializeMessageQueue()
{
const int MAX_WAIT_TIME_SECONDS = 60;
var worker = new System.Threading.Thread(InitializeMessageQueueWork);
worker.Start();
var dtWaitStart = DateTime.UtcNow;
// Wait a maximum of 60 seconds
if (!worker.Join(MAX_WAIT_TIME_SECONDS * 1000))
{
worker.Abort();
m_MsgQueueInitSuccess = false;
LogWarning("Unable to initialize the message queue (timeout after " + MAX_WAIT_TIME_SECONDS + " seconds)");
return;
}
var elaspedTime = DateTime.UtcNow.Subtract(dtWaitStart).TotalSeconds;
if (elaspedTime > 25)
{
ReportStatus("Connection to the message queue was slow, taking " + (int)elaspedTime + " seconds");
}
}
示例13: GameMain
//.........这里部分代码省略.........
userGuess[selection - 1] = 6;
RanderPlayerGuess(idx);
}
}
else if (key.KeyChar == 'm')
{
//check if hard dif if not do nothing
//draw magenta in cur selection
if (mColors >= 7)
{
userGuess[selection - 1] = 7;
RanderPlayerGuess(idx);
}
}
else if (key.KeyChar == 'g')
{
//check if hard dif if not do nothing
//draw gray in cur selection
if (mColors == 8)
{
userGuess[selection - 1] = 8;
RanderPlayerGuess(idx);
}
}
else if (key.KeyChar == 13)
{
//check to see if the guess is complete
if (userGuess[0] != 0 && userGuess[1] != 0 && userGuess[2] != 0 && userGuess[3] != 0)
{
//compere guess whit hiddien code
//show feedback
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
if (Identical(userGuess[i], hCode[j]))
{
if (i == j)
{
fBack[i] = 2;
break;
}
else
{
fBack[i] = 1;
}
}
}
}
guesses++;
RanderKeyPegs(idx);
RanderPlayerGuess(idx);
if (fBack[0] == 2 && fBack[1] == 2 && fBack[2] == 2 && fBack[3] == 2)
{
timerThread.Abort();
timerThread.Join();
RanderHiddienCode();
win = 1;
for (int i = 0; i < 4; i++)
{
fBack[i] = 0;
userGuess[i] = 0;
}
PlaySongWin();
System.Threading.Thread.Sleep(1500);
GameOver();
}
else if (guesses == mGuesses)
{
timerThread.Abort();
timerThread.Join();
RanderHiddienCode();
win = 0;
for (int i = 0; i < 4; i++)
{
fBack[i] = 0;
userGuess[i] = 0;
}
PlaySongLose();
System.Threading.Thread.Sleep(1500);
GameOver();
}
for (int i = 0; i < 4; i++)
{
fBack[i] = 0;
userGuess[i] = 0;
}
idx = idx - 2;
selection = 1;
RanderPegSelection(selection, idx);
}
}
else if (key.KeyChar == 'n')
{
//used for testing
RanderHiddienCode();
}
}
while (1 != 2);
}
示例14: SafeGetRequestOrResponseStream
/// <summary>
/// Helper function that invokes a thread and the GetRequestStream() or GetResponse() method
/// </summary>
/// <param name="req">The request to invoke the method on</param>
/// <param name="getRequest">A value indicating if the invoked method should be GetRequestStream() or GetResponse()</param>
/// <returns>Either a System.IO.Stream or a System.Net.WebResponse object</returns>
private static object SafeGetRequestOrResponseStream(System.Net.WebRequest req, bool getRequest)
{
object[] args = new object[] { req, getRequest, null };
System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(RunSafeGetRequest));
try
{
//We use the timeout to determine how long we should wait
int waitTime = req.Timeout == System.Threading.Timeout.Infinite ? DEFAULT_RESPONSE_TIMEOUT : req.Timeout;
t.Start(args);
if (t.Join(waitTime))
{
if (args[2] == null)
throw new Exception(string.Format(Strings.Utility.UnexpectedRequestResultError, "null", ""));
else if (args[2] is Exception)
throw (Exception)args[2];
if (getRequest && args[2] is System.IO.Stream)
return (System.IO.Stream)args[2];
else if (!getRequest && args[2] is System.Net.WebResponse)
return (System.Net.WebResponse)args[2];
throw new Exception(string.Format(Strings.Utility.UnexpectedRequestResultError, args[2].GetType(), args[2].ToString()));
}
else
{
t.Abort();
throw new System.Net.WebException(Strings.Utility.TimeoutException, null, System.Net.WebExceptionStatus.Timeout, null);
}
}
catch
{
try { t.Abort(); }
catch { }
throw;
}
}
示例15: cmdCancel_Click
private void cmdCancel_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Bạn có muốn hủy việc download file hay không?", "RISlink", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
try
{
if (t==null && t.ThreadState != System.Threading.ThreadState.Running) return;
t.Abort();
t = null;
lblCapacity.Visible = false;
txtDir.Enabled = true;
txtURL.Enabled = true;
cmdDir.Enabled = true;
cmdLoad.Enabled = true;
lblStatus.Visible = false;
picLoading.Visible = false;
cmdCancel.Visible = false;
cmdOpen.Visible = false;
lblResult.Visible = false;
cmdLoad.Focus();
}
catch
{
lblCapacity.Visible = false;
txtDir.Enabled = true;
txtURL.Enabled = true;
cmdDir.Enabled = true;
cmdLoad.Enabled = true;
lblStatus.Visible = false;
picLoading.Visible = false;
cmdCancel.Visible = false;
cmdOpen.Visible = false;
lblResult.Visible = false;
cmdLoad.Focus();
t.Abort();
t = null;
}
}
}