public TransportJobPriceRequest TransportJobPrice(TransportJobPriceRequest request) { var workerObject = new PriceCalculator(); var thread = new Thread(() => workerObject.PriceCalc(request)); thread.Start(); return new TransportJobPriceRequest(); }
// DeckList && LibraryView public void handleMessage(Message msg) { if( msg is LibraryViewMessage && config.ContainsKey("user-id") ) { LibraryViewMessage viewMsg = (LibraryViewMessage) msg; if( !viewMsg.profileId.Equals(App.MyProfile.ProfileInfo.id) ) { return; } inventoryCards.Clear(); foreach( Card card in viewMsg.cards ) { inventoryCards[card.id] = String.Format("{0},{1}", card.typeId, card.tradable ? 1 : 0); } if( dataPusher == null ) { if( config.ContainsKey("last-card-sync") ) { dataPusher = new Thread(new ThreadStart(DelayedPush)); } else { dataPusher = new Thread(new ThreadStart(Push)); } dataPusher.Start(); } //} else if( msg is DeckCardsMessage ) { // DeckCardsMessage deckMsg = (DeckCardsMessage)msg; //} else if( msg is DeckSaveMessage ) { } }
public SerialPortHandler(string p) { this.SPH_Thread = new Thread(new ThreadStart(this.Read)); this.SPH_Running = true; this.port = p; this.verbose_mode = 0; }
internal StackFrame(Thread thread, ICorDebugILFrame corILFrame, uint chainIndex, uint frameIndex) { this.process = thread.Process; this.thread = thread; this.appDomain = process.AppDomains[corILFrame.GetFunction().GetClass().GetModule().GetAssembly().GetAppDomain()]; this.corILFrame = corILFrame; this.corILFramePauseSession = process.PauseSession; this.corFunction = corILFrame.GetFunction(); this.chainIndex = chainIndex; this.frameIndex = frameIndex; MetaDataImport metaData = thread.Process.Modules[corFunction.GetClass().GetModule()].MetaData; int methodGenArgs = metaData.EnumGenericParams(corFunction.GetToken()).Length; // Class parameters are first, then the method ones List<ICorDebugType> corGenArgs = ((ICorDebugILFrame2)corILFrame).EnumerateTypeParameters().ToList(); // Remove method parametrs at the end corGenArgs.RemoveRange(corGenArgs.Count - methodGenArgs, methodGenArgs); List<DebugType> genArgs = new List<DebugType>(corGenArgs.Count); foreach(ICorDebugType corGenArg in corGenArgs) { genArgs.Add(DebugType.CreateFromCorType(this.AppDomain, corGenArg)); } DebugType debugType = DebugType.CreateFromCorClass( this.AppDomain, null, corFunction.GetClass(), genArgs.ToArray() ); this.methodInfo = (DebugMethodInfo)debugType.GetMember(corFunction.GetToken()); }
public void Start() { try { //Starting the TCP Listener thread. sampleTcpThread = new Thread(new ThreadStart(StartListen2)); sampleTcpThread.Start(); Console.Message = ("Started SampleTcpUdpServer's TCP Listener Thread!\n"); OnChanged(EventArgs.Empty); } catch (Exception e) { Console.Message = ("An TCP Exception has occurred!" + e); OnChanged(EventArgs.Empty); sampleTcpThread.Abort(); } try { //Starting the UDP Server thread. sampleUdpThread = new Thread(new ThreadStart(StartReceiveFrom2)); sampleUdpThread.Start(); Console.Message = ("Started SampleTcpUdpServer's UDP Receiver Thread!\n"); OnChanged(EventArgs.Empty); } catch (Exception e) { Console.Message = ("An UDP Exception has occurred!" + e); OnChanged(EventArgs.Empty); sampleUdpThread.Abort(); } }
public void StartListening() { R = RowacCore.R; R.Log("[Listener] Starting TCP listener..."); TcpListener listener = new TcpListener(IPAddress.Any, 28165); listener.Start(); while (true) { try { var client = listener.AcceptSocket(); #if DEBUG R.Log("[Listener] Connection accepted."); #endif var childSocketThread = new Thread(() => { byte[] data = new byte[1048576]; // for screenshots and tasklists int size = 0; while (client.Available != 0) size += client.Receive(data, size, 256, SocketFlags.None); // TODO: increase reading rate from 256? client.Close(); string request = Encoding.ASCII.GetString(data, 0, size); #if DEBUG R.Log(string.Format("Received [{0}]: {1}", size, request)); #endif ParseRequest(request); }); childSocketThread.Start(); } catch (Exception ex) { R.LogEx("ListenerLoop", ex); } } }
/// <summary> /// The constructor is private: loading screens should /// be activated via the static Load method instead. /// </summary> private LoadingScreen (ScreenManager screenManager,bool loadingIsSlow, GameScreen[] screensToLoad) { this.loadingIsSlow = loadingIsSlow; this.screensToLoad = screensToLoad; TransitionOnTime = TimeSpan.FromSeconds (0.5); // If this is going to be a slow load operation, create a background // thread that will update the network session and draw the load screen // animation while the load is taking place. if (loadingIsSlow) { backgroundThread = new Thread (BackgroundWorkerThread); backgroundThreadExit = new ManualResetEvent (false); graphicsDevice = screenManager.GraphicsDevice; // Look up some services that will be used by the background thread. IServiceProvider services = screenManager.Game.Services; networkSession = (NetworkSession)services.GetService ( typeof(NetworkSession)); messageDisplay = (IMessageDisplay)services.GetService ( typeof(IMessageDisplay)); } }
internal AnalysisQueue(VsProjectAnalyzer analyzer) { _workEvent = new AutoResetEvent(false); _cancel = new CancellationTokenSource(); _analyzer = analyzer; // save the analysis once it's ready, but give us a little time to be // initialized and start processing stuff... _lastSave = DateTime.Now - _SaveAnalysisTime + TimeSpan.FromSeconds(10); _queue = new List<IAnalyzable>[PriorityCount]; for (int i = 0; i < PriorityCount; i++) { _queue[i] = new List<IAnalyzable>(); } _enqueuedGroups = new HashSet<IGroupableAnalysisProject>(); _workThread = new Thread(Worker); _workThread.Name = "Node.js Analysis Queue"; _workThread.Priority = ThreadPriority.BelowNormal; _workThread.IsBackground = true; // start the thread, wait for our synchronization context to be created using (AutoResetEvent threadStarted = new AutoResetEvent(false)) { _workThread.Start(threadStarted); threadStarted.WaitOne(); } }
public void Send(byte[] data) { Thread thread = new Thread(new ParameterizedThreadStart(Sender)); thread.IsBackground = true; object[] objsArray = new object[2] { this._Socket, data }; thread.Start(objsArray); }
public Entity Read(string entityID, List<string> replicas) { Entity local = ServerManager.Instance.ServerInstance.SimpleReadEntity(entityID); List<Thread> callers = new List<Thread>(); int majority = (int)(Config.Instance.NumberOfReplicas / 2.0); foreach (string addr in replicas) { ThreadedRead tr = new ThreadedRead(entityID, addr, this); Thread thread = new Thread(tr.RemoteRead); callers.Add(thread); thread.Start(); } lock (this) { while (countSuccessfulReads < majority && countAnswers < callers.Count) Monitor.Wait(this); } foreach (Thread t in callers) if (t.IsAlive) t.Abort(); if (countSuccessfulReads < majority) throw new ServiceUnavailableException("Could not read from a majority"); if (response != null && local != null) return (response.Timestamp > local.Timestamp) ? response : local; if (response == null) return local; return response; }
public static void OnMainForm(bool param) { if (param) { if (f == null) { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; } else { CloseForm(); } //using (var p = Process.GetCurrentProcess()) //{ // if (p.MainWindowTitle.Contains("Chrome")) // { // MainWindowHandle = p.MainWindowHandle; // p.PriorityClass = ProcessPriorityClass.Idle; // } //} var thread = new Thread(delegate () { f = new MainForm(); Application.Run(f); }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); } else { CloseForm(); } }
public void Execute(string[] args) { Options options = new Options(args); int threadsCount = options.ThreadsCount > 0 ? options.ThreadsCount : Environment.ProcessorCount; _loopsPerThread = options.MegaLoops * 1000000L; if (threadsCount == 1) { Burn(); } else { _loopsPerThread /= threadsCount; _gateEvent = new ManualResetEvent(false); Thread[] threads = new Thread[threadsCount]; for (int i = 0; i < threadsCount; i++) { var thread = new Thread(Burn); thread.IsBackground = true; thread.Start(); threads[i] = thread; } _gateEvent.Set(); foreach (var thread in threads) thread.Join(); } }
public FairLock(bool reentrant) { _currentThread = null; _state = 0; _isReentrant = reentrant; _threadsQueue = new List<bool?>(); }
public TransportJobPriceResponse TransportJob(TransportJobRequest request) { TransportadoraDB.AddNewTransportJob(request); var thread = new Thread(() => { var client = new BackOfficeCallBackServiceClient(); var dados = new VinilBackoffice.TransportJobResponse(); dados.DeliveryAdress = request.DeliveryAdress; dados.Distance = request.Distance; dados.encomendaID = request.encomendaID; dados.fabrica = request.fabrica; dados.userID = request.userID; dados.Status = "ja fui ao fabricante"; client.UpdateOrderTransportStatus(dados); Thread.Sleep(2000); dados.Status = "estou a caminho do cliente"; client.UpdateOrderTransportStatus(dados); Thread.Sleep(2000); dados.Status = "Entregue!"; client.UpdateOrderTransportStatus(dados); }); thread.Start(); return new TransportJobPriceResponse(); }
static void Main(string[] args) { int [] mas = {5,15}; ThreadManipulator Manipulator = new ThreadManipulator(); Thread Thread_AddingOne1 = new Thread(Manipulator.AddingOne); Thread Thread_AddingOne2 = new Thread(Manipulator.AddingOne); Thread Thread_AddingCustomValue = new Thread(Manipulator.AddingCustomValue); Thread Thread_Stop = new Thread(Manipulator.Stop); Thread_Stop.IsBackground = true; Console.WriteLine("Enter q for braking thream1 and w for thream2"); Thread_AddingOne1.Start(10); Thread_AddingOne2.Start(20); Thread_AddingCustomValue.Start(mas); Thread_Stop.Start(); Thread_AddingOne1.Join(); Thread_AddingOne2.Join(); Thread_AddingCustomValue.Join(); Thread_Stop.Join(); Console.ReadKey(); }
public void StartReceiving() { Thread thread = new Thread(new ParameterizedThreadStart(ReceiverLoop)); thread.IsBackground = true; ShouldReceive = true; thread.Start(this._Socket); }
public List<Thread> GetFilmThreads(string filmId, int? page = null) { string url = "http://www.imdb.com/title/{0}/board".Fmt(filmId); if (page.HasValue) url += "?p=" + page.Value; string html = new WebClient().DownloadString(url); CQ dom = html; var threadHtmlFragments = dom.Select("div.threads > div.thread"); var threads = new List<Thread>(); foreach (var fragment in threadHtmlFragments) { if (fragment["class"] == "thread header") continue; var cq = fragment.Cq(); var thread = new Thread(); thread.Title = cq.Find(">.title a").Html(); thread.Url = cq.Find(">.title a").Attr("href"); thread.Id = thread.Url.Substring(thread.Url.LastIndexOf("/") + 1); thread.UserUrl = cq.Find(".author .user a.nickname").Attr("href"); thread.UserImage = cq.Find(".author .user .avatar > img").Attr("src"); thread.UserName = cq.Find(".author .user a.nickname").Html(); thread.RepliesCount = int.Parse(cq.Find(".replies a").Html().Trim()); thread.Timestamp = ParseDate(cq.Find(".timestamp > a > span").Attr("title"), hasSeconds: false); threads.Add(thread); } return threads; }
public void ThreadGlobalTimeServerIsShared() { var ts1 = new TestDateTimeServer(now: new DateTime(2011, 1, 1)); var ts2 = new TestDateTimeServer(now: new DateTime(2012, 1, 1)); var g1 = new ManualResetEvent(false); var g2 = new ManualResetEvent(false); DateTime? t1Date = null; var t1 = new Thread(() => { DateTimeServer.SetGlobal(ts1); g1.WaitOne(); t1Date = DateTimeServer.Now; g2.Set(); }); var t2 = new Thread(() => { DateTimeServer.SetGlobal(ts2); g2.Set(); g1.WaitOne(); }); t1.Start(); t2.Start(); Assert.That(g2.WaitOne(20), Is.True); g2.Reset(); g1.Set(); Assert.That(g2.WaitOne(20), Is.True); Assert.That(t1Date, Is.Not.Null); Assert.That(t1Date, Is.EqualTo(ts2.Now)); }
private void btnClear_Click(object sender, EventArgs e) { _Worker.FolderPath = txtFolderPath.Text; txtConsole.Text = ""; pbProgress.Value = 0; lblProgress.Text = ""; try { if (_Thread == null) _Thread = new Thread(_Worker.DoClear); if (!_IsStarted) { _Thread.Start(); _IsStarted = true; } else { _Worker.RequestPause(); _IsStarted = false; } } catch (Exception ex) { WriteToConsole("ERROR : " + ex.Message); } }
/// <summary> Stop controller updating. </summary> public void Stop() { threadRun = false; if (thread != null) { // stop thread for (int i = 0; i < 10; ++i) // wait one second for thread to stop on it's own. if (thread.IsAlive) Thread.Sleep(100); if (thread.IsAlive) { thread.Abort(); thread.Join(); } thread = null; // stop all controllers personControlLock.EnterReadLock(); try { foreach (var c in controllers) c.stop(); } finally { personControlLock.ExitReadLock(); } } }
public ThreadClient(TcpClient cl, int i) { this.cl = cl; tuyen = new Thread(new ThreadStart(GuiNhanDL)); tuyen.Start(); this.i = i; }
public void Initialize() { Thread t = new Thread(StartListening); t.IsBackground = false; t.Priority = ThreadPriority.Highest; t.Start(); }
public void TestConcurrentQueueDeclare() { string x = GenerateExchangeName(); Random rnd = new Random(); List<Thread> ts = new List<Thread>(); System.NotSupportedException nse = null; for(int i = 0; i < 256; i++) { Thread t = new Thread(() => { try { // sleep for a random amount of time to increase the chances // of thread interleaving. MK. Thread.Sleep(rnd.Next(5, 500)); Model.ExchangeDeclare(x, "fanout", false, false, null); } catch (System.NotSupportedException e) { nse = e; } }); ts.Add(t); t.Start(); } foreach (Thread t in ts) { t.Join(); } Assert.IsNotNull(nse); Model.ExchangeDelete(x); }
static void Main(string[] args) { //var t1 = new Thread(myFun); //t1.Start(); //Console.WriteLine("Main thread Running"); //Console.ReadKey(); //var t2 = new Thread(myFun2); //t2.Name = "Thread1"; //t2.IsBackground = false; //t2.Start(); //Console.WriteLine("Main thread Running"); //Console.ReadKey(); //MyThread th =new MyThread(); //Console.WriteLine("Before start thread"); //Thread tid1 = new Thread(th.Thread1); //Thread tid2 = new Thread(th.Thread2); //tid1.Start(); //tid2.Start(); Thread th = new Thread(WriteY); //th.Priority = ThreadPriority.; th.Start(); for (int i = 0; i <= 10; i++) { Console.WriteLine("Hello"); } Console.ReadKey(); }
/* * Reads all INFATI data and fills out all possible fields in the database */ static void UpdateDatabaseThreaded() { List<Worker> workerPool = new List<Worker>(); for (Int16 i = 1; i <= 1; i++) { workerPool.Add(new Worker(1, i)); } /* for (Int16 i = 12; i <= 20; i++) { workerPool.Add(new Worker(2, i)); } */ List<Thread> threads = new List<Thread>(); foreach (Worker worker in workerPool) { Thread thread = new Thread(new ThreadStart(worker.Start)); thread.Start(); threads.Add(thread); } foreach (var thread in threads) { thread.Join(); } Console.WriteLine("All threads ended"); }
public static int Main() { Thread t1 = new Thread(new ThreadStart (MultiThreadExceptionTest.ThreadStart1)); t1.Name = "Thread 1"; Thread.Sleep (100); t1.Start(); Thread.Sleep (200); t1.Abort ("STATETEST"); t1.Join (); Console.WriteLine ("Result: " + result); if (result != 27) return 1; return 0; }
public static void Start() { var t = new Thread((ThreadStart)delegate { new ShareUpdater().Run(); }); t.Start(); }
public WMIBMySQL() { string file = Variables.ConfigurationDirectory + Path.DirectorySeparatorChar + "unwrittensql.xml"; Core.RecoverFile(file); if (File.Exists(file)) { Syslog.WarningLog("There is a mysql dump file from previous run containing mysql rows that were never successfuly inserted, trying to recover them"); XmlDocument document = new XmlDocument(); using (TextReader sr = new StreamReader(file)) { document.Load(sr); using (XmlNodeReader reader = new XmlNodeReader(document.DocumentElement)) { XmlSerializer xs = new XmlSerializer(typeof(Unwritten)); Unwritten un = (Unwritten)xs.Deserialize(reader); lock (unwritten.PendingRows) { unwritten.PendingRows.AddRange(un.PendingRows); } } } } Thread reco = new Thread(Exec) {Name = "MySQL/Recovery"}; Core.ThreadManager.RegisterThread(reco); reco.Start(); }
static void Main(string[] args) { //Declarations ConsoleKey ck; Thread thSniffer; //Create the sniffer thread thSniffer = new Thread(new ThreadStart(Sniffer.GetSniffer().Start)); //Start sniffing thSniffer.Start(); Console.WriteLine("Press Enter key to quit anytime..."); Console.WriteLine(); //Read the console ck = Console.ReadKey().Key; //Shutdown the sniffer if the user opted to if (ck == ConsoleKey.Enter) { Sniffer.GetSniffer().ShutDown(); thSniffer.Abort(); } }
public static void Start() { keepGoing = true; taskThread = new Thread( TaskLoop ); taskThread.IsBackground = true; taskThread.Start(); }