public static extern IntPtr CreateThread( IntPtr lpThreadAttributes, uint dwStackSize, ThreadProc lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, out uint dwThreadId);
public static extern IntPtr CreateThread( IntPtr lpThreadAttributes, int dwStackSize, ThreadProc lpStartAddress, IntPtr lpParameter, int dwCreationFlags, out int lpThreadId);
public WorkerQueuePrivate(ThreadProc threadProc, int numWorkerThreads, object[] tasks) { ThreadList = new List <ThreadObj>(); int i; this.ThreadProc = threadProc; this.NumWorkerThreads = numWorkerThreads; foreach (object task in tasks) { TaskQueue.Enqueue(task); } RaisedException = null; for (i = 0; i < numWorkerThreads; i++) { ThreadObj t = new ThreadObj(WorkerThread); ThreadList.Add(t); } foreach (ThreadObj t in ThreadList) { t.WaitForEnd(); } if (RaisedException != null) { throw RaisedException; } }
public WorkerQueuePrivate(ThreadProc thread_proc, int num_worker_threads, object[] tasks) { thread_list = new List <ThreadObj>(); int i; this.thread_proc = thread_proc; this.num_worker_threads = num_worker_threads; foreach (object task in tasks) { taskQueue.Enqueue(task); } raised_exception = null; for (i = 0; i < num_worker_threads; i++) { ThreadObj t = new ThreadObj(worker_thread); thread_list.Add(t); } foreach (ThreadObj t in thread_list) { t.WaitForEnd(); } if (raised_exception != null) { throw raised_exception; } }
public static ThreadObj[] StartMany(int num, ThreadProc proc, object?param = null, bool isBackground = false) { List <ThreadObj> ret = new List <ThreadObj>(); for (int i = 0; i < num; i++) { ThreadObj t = new ThreadObj(proc, param, 0, i, isBackground: isBackground); ret.Add(t); } return(ret.ToArray()); }
/// <summary> /// 启动策略执行线程 /// </summary> public void RUN() { ThreadProc _thread = new ThreadProc(_threadProc); excutedThread = new Thread(new ThreadStart(_thread)); //获取订阅列表 List <managedsecurityindex> subscribelist = new List <managedsecurityindex>(); if (Type == "OPEN") { //开仓 open_args args = InitArgs(open_para.WeightList, LiStockOrder, CT, open_para.OP, open_para.INDEX, HD); m_strategy_open.init(args); subscribelist = m_strategy_open.getsubscribelist().ToList(); } else if (Type == "CLOSE") { //平仓 //预付费率和期货开仓点 close_args args = InitArgs(close_para.WeightList, LiStockOrder, CT, close_para.INDEX, HD, (double)close_para.SD, (double)close_para.SA, (double)close_para.COE, close_para.SP, (double)close_para.SD, (double)close_para.PE, close_para.Charge); m_strategy_close.init(args); subscribelist = m_strategy_close.getsubscribelist().ToList(); } RunningTime = DateTime.Now; //获取订阅列表 bool change = false; foreach (var item in subscribelist) { _subscribe.Add(item.cSecurity_code); change = true; } bSubscribeChange = change; excutedThread.Start(); Thread.Sleep(100); }
public static ThreadInfo[] StartThreadsEx(ThreadProc proc) { if (CfgWorkThreads != 1) { int oldThreads = CfgWorkThreads; CfgWorkThreads = 5 * CfgWorkThreads; ThreadInfo[] ret = StartThreads(delegate(object arg) { proc(arg as ThreadInfo); }); CfgWorkThreads = oldThreads; return(ret); } else { return(StartThreads(delegate(object arg) { proc(arg as ThreadInfo); })); } }
void init(ThreadProc threadProc, object userObject, int stacksize) { if (stacksize == 0) { stacksize = defaultStackSize; } this.proc = threadProc; this.userObject = userObject; waitInit = new EventWaitHandle(false, EventResetMode.AutoReset); waitEnd = new EventWaitHandle(false, EventResetMode.ManualReset); waitInitForUser = new EventWaitHandle(false, EventResetMode.ManualReset); this.thread = new Thread(new ParameterizedThreadStart(commonThreadProc), stacksize); this.thread.Start(this); waitInit.WaitOne(); }
public ThreadObj(ThreadProc threadProc, object?userObject = null, int stacksize = 0, int index = 0, string?name = null, bool isBackground = false, ThreadPriority priority = ThreadPriority.Normal) { if (stacksize == 0) { stacksize = DefaultStackSize; } if (name._IsEmpty()) { try { name = threadProc.Target?.ToString() ?? "(unknown)" + "." + threadProc.Method.Name + "()"; } catch { try { name = threadProc.Method.DeclaringType + "." + threadProc.Method.Name + "()"; } catch { } } } this.Name = name ?? "(unknown)"; this.Proc = threadProc; this.UserObject = userObject; this.Index = index; WaitEnd = new EventWaitHandle(false, EventResetMode.ManualReset); WaitEndAsync = new AsyncManualResetEvent(); WaitInitForUser = new EventWaitHandle(false, EventResetMode.ManualReset); WaitInitForUserAsync = new AsyncManualResetEvent(); NumCurrentThreads.Increment(); this.Thread = new Thread(new ParameterizedThreadStart(commonThreadProc), stacksize); if (this.Name._IsFilled()) { this.Thread.Name = this.Name; } this.Thread.IsBackground = isBackground; if (priority != ThreadPriority.Normal) { this.Thread.Priority = priority; } this.Thread.Start(this); }
public ThreadObj(ThreadProc threadProc) { init(threadProc, null, 0); }
public static void ProcessWorkQueue(ThreadProc thread_proc, int num_worker_threads, object[] tasks) { WorkerQueuePrivate q = new WorkerQueuePrivate(thread_proc, num_worker_threads, tasks); }
void init(ThreadProc threadProc, object userObject, int stacksize) { if (stacksize == 0) { stacksize = defaultStackSize; } this.proc = threadProc; this.userObject = userObject; waitInit = new EventWaitHandle(false, EventResetMode.AutoReset); waitEnd = new EventWaitHandle(false, EventResetMode.ManualReset); waitInitForUser = new EventWaitHandle(false, EventResetMode.ManualReset); this.thread = new Thread(new ParameterizedThreadStart(commonThreadProc), stacksize); this.thread.Start(this); waitInit.WaitOne(); }
public ThreadObj(ThreadProc threadProc, object userObject, int stacksize) { init(threadProc, userObject, stacksize); }
public ThreadObj(ThreadProc threadProc, object userObject) { init(threadProc, userObject, 0); }
// Main function static void Mainly(string[] args) { int pid = Process.GetCurrentProcess().Id; if (args.Length == 0) { MessageBox.Show("Pid " + pid + ":Started Parent process"); //Console.WriteLine("Pid {0}:Started Parent process", pid); // Spawn the child //string fileName = Process.GetCurrentProcess().MainModule.FileName.Replace(".vshost", ""); string fileName = Directory.GetCurrentDirectory() + "\\gw.exe"; // Get thread proc as an IntPtr, which we can then pass to the 2nd-process. ThreadProc proc = new ThreadProc(MyThreadProc); IntPtr fpProc = Marshal.GetFunctionPointerForDelegate(proc); // Spin up the other process, and pass our pid and function pointer so that it can // use that to call CreateRemoteThraed string arg = String.Format("{0} {1}", pid, fpProc); ProcessStartInfo info = new ProcessStartInfo(fileName, arg); info.UseShellExecute = false; // share console, output is interlaces. Process processChild = Process.Start(info); processChild.WaitForExit(); return; } else { MessageBox.Show("Pid " + pid + ":Started Child process"); //Console.WriteLine("Pid {0}:Started Child process", pid); uint pidParent = uint.Parse(args[0]); IntPtr fpProc = new IntPtr(int.Parse(args[1])); IntPtr hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, pidParent); uint dwThreadId; // Create a thread in the first process. IntPtr hThread = CreateRemoteThread( hProcess, IntPtr.Zero, 0, fpProc, new IntPtr(6789), 0, out dwThreadId); WaitForThreadToExit(hThread); return; } }
public ThreadObj(ThreadProc threadProc, object userObject, int stacksize) { init(threadProc, userObject, stacksize); }
public WorkerQueuePrivate(ThreadProc thread_proc, int num_worker_threads, object[] tasks) { thread_list = new List<ThreadObj>(); int i; this.thread_proc = thread_proc; this.num_worker_threads = num_worker_threads; foreach (object task in tasks) { taskQueue.Enqueue(task); } raised_exception = null; for (i = 0; i < num_worker_threads; i++) { ThreadObj t = new ThreadObj(worker_thread); thread_list.Add(t); } foreach (ThreadObj t in thread_list) { t.WaitForEnd(); } if (raised_exception != null) { throw raised_exception; } }
public static extern IntPtr CreateThread(IntPtr securityAttributes, UIntPtr stackSize, ThreadProc proc, IntPtr parameter, uint flags, out uint id);
/// <summary> /// 启动策略执行线程 /// </summary> public void RUN() { ThreadProc _thread = new ThreadProc(_threadProc); excutedThread = new Thread(new ThreadStart(_thread)); //获取订阅列表 List<managedsecurityindex> subscribelist = new List<managedsecurityindex>(); if (Type == "OPEN") { //开仓 open_args args = InitArgs(open_para.WeightList, LiStockOrder, CT, open_para.OP, open_para.INDEX, HD); m_strategy_open.init(args); subscribelist = m_strategy_open.getsubscribelist().ToList(); } else if (Type == "CLOSE") { //平仓 //预付费率和期货开仓点 close_args args = InitArgs(close_para.WeightList, LiStockOrder, CT, close_para.INDEX, HD, (double)close_para.SD, (double)close_para.SA, (double)close_para.COE, close_para.SP, (double)close_para.SD, (double)close_para.PE, close_para.Charge); m_strategy_close.init(args); subscribelist = m_strategy_close.getsubscribelist().ToList(); } RunningTime = DateTime.Now; //获取订阅列表 bool change = false; foreach (var item in subscribelist) { _subscribe.Add(item.cSecurity_code); change = true; } bSubscribeChange = change; excutedThread.Start(); Thread.Sleep(100); }
public static ThreadObj Start(ThreadProc proc, object?param = null, bool isBackground = false) { return(new ThreadObj(proc, param, isBackground: isBackground)); }
public static extern bool QueueUserWorkItem(ThreadProc Function, [In] IntPtr Context, WT Flags);
public ThreadObj(ThreadProc threadProc, int stacksize) { init(threadProc, null, stacksize); }
public static void ProcessWorkQueue(ThreadProc thread_proc, int num_worker_threads, object[] tasks) { WorkerQueuePrivate q = new WorkerQueuePrivate(thread_proc, num_worker_threads, tasks); }
public ThreadObj(ThreadProc threadProc, object userObject) { init(threadProc, userObject, 0); }
public static ThreadInfo[] StartThreads(ThreadProc proc) { return(StartThreads(delegate(object arg) { proc(arg as ThreadInfo); })); }
public ThreadObj(ThreadProc threadProc) { init(threadProc, null, 0); }
// Other variations of create thread static void OtherMain(string[] args) { IntPtr fpProc = IntPtr.Zero; ThreadProc proc = new ThreadProc(MyThreadProc); fpProc = Marshal.GetFunctionPointerForDelegate(proc); uint dwThreadId; #if false IntPtr hThread = CreateThreadRaw( IntPtr.Zero, 0, fpProc, new IntPtr(1234), 0, // flags out dwThreadId); #elif false IntPtr hThread = CreateThread( IntPtr.Zero, 0, proc, new IntPtr(1234), 0, // flags out dwThreadId); #else IntPtr hThisProcess = GetCurrentProcess(); IntPtr hThread = CreateRemoteThread( hThisProcess, IntPtr.Zero, 0, fpProc, new IntPtr(5678), 0, out dwThreadId); #endif WaitForThreadToExit(hThread); }
public ProcThreadWrapper(ThreadProc method) : base() { _method = method; }
public ThreadObj(ThreadProc threadProc, int stacksize) { init(threadProc, null, stacksize); }