/// <summary> /// Starts the task, optionally in a background thread. /// </summary> /// <remarks> /// If the task is started in a background thread, the task will be terminated in the /// calling thread terminates. Otherwise, the calling thread will not terminate until /// the task completes. /// </remarks> /// <param name="p_booRunInBackground">Whether the task should be run in a background thread.</param> /// <param name="p_objArgs">Arguments to pass to the task execution method.</param> /// <seealso cref="Start(object[])"/> /// <seealso cref="StartWait(object[])"/> /// <seealso cref="StartWait(bool, object[])"/> protected void Start(bool p_booRunInBackground, params object[] p_objArgs) { //Not sure if BeginInvoke/EndInvoke or Thread is better for exception handling // it seem BeginInvoke/EndInvoke is not ideal. exceptions are trapped and rethrown // in EndThreadInvokeHandler when EnInvoke is called, so the debugger // breaks in EndThreadInvokeHandler, and not where the exception is actually thrown //however, I was using threads here, and I changed. according the the SVN log, I made // the switch to improve exception handling. not sure what issue I was encountering. // maybe the issue was actually related to the fact that some operations at the time // were wrapped in unneccessary threads - that issue has since been resolved // //I would like to find, and then document, a specific case where the thread // provides an advantage over BeginInvoke/EndInvoke. in StartWait(), // I seem to be observing the debugger break on the source of the exception, even // with BeginInvoke/EndInvoke, so I would like a conter-example. //example of BeginInvoke/EndInvoke breaking on exception source: if I insert: // if (System.Windows.Forms.MessageBox.Show("Now?", "CRASH", System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) // throw new DirectoryNotFoundException("DUMMY"); // as the first line of Archive.public byte[] GetFileContents(string p_strPath) // StartWait() breaks on said line. /*Func<object, object> dlg = new Func<object, object>(RunThreadedWork); * IAsyncResult ar = dlg.BeginInvoke(args, EndThreadInvokeHandler, args);*/ TrackedThread thdWork = new TrackedThread(RunThread); thdWork.Thread.IsBackground = p_booRunInBackground; thdWork.Start(p_objArgs); }
public void SetAxisAndInitGUI(HardwareController hwc, Axis axis) { HWC = hwc; MyAxis = axis; Data.AxisName = MyAxis.ControlIdent; EnableChange(axis, axis.IsEnable); HasFaultChange(axis, axis.HasFault); this.Data.AbsPosStr = Axis.SConvertIntToStr(MyAxis.Position, true); this.Data.RelPosStr = Axis.SConvertIntToStr(HWC.ConvertCoordinatesAlways(MyAxis.ControlIdent, -MyAxis.Position) * (-1), true); //Verbinde Notifyer MyAxis.IsEnableChanged += EnableChange; MyAxis.HasFaultChange += HasFaultChange; MyAxis.PositionChange += PositionChange; MyAxis.VelocityChange += VelocityChange; //Load Values DataSafe ds = new DataSafe(Paths.SettingsPath, "MainWindow"); Speed = ds.Ints[axis.ControlIdent + "-FR-Speed", 0]; Distance = ds.Ints[axis.ControlIdent + "-FR-Distance", 0]; UseDistance = ds.Bools[axis.ControlIdent + "-FR-UseDis", false]; DisplayFreeRunValues(); FreeRunThread = new TrackedThread("Free Run Distance Thread: " + MyAxis, this.FreeRunThreadMethod); FreeRunQueue = new Queue <Action>(); FreeRunThread.Start(); }
/// <summary> /// Installs the mod. /// </summary> public void Install() { TrackedThread thdWorker = new TrackedThread(RunTasks); thdWorker.Thread.IsBackground = false; thdWorker.Start(); }
public static void StopThread2() { if (State_2 != ScriptThreadState.Waiting) { try { Thread_2.Thread.Abort(); if (Thread_2_Obj != null) { lock (Thread_2_Obj) { Thread_2_Obj = null; } } GC.Collect(); GC.WaitForPendingFinalizers(); Thread_2 = new TrackedThread("Script Thread 2", Thread_2_Handle, true); Thread_2.Start(); Node.SetPaused(2, false); } catch { #warning Implement error handling } } }
public void Load() { TrackedThread tt = new TrackedThread("LoadingWindow Loading Thread", LoadingThread); tt.Start(); this.ShowDialog(); }
public Timekeeper(float?duration = null) { this.duration = duration; trackedThread = new TrackedThread(() => Timer()); trackedThread.Thread.IsBackground = true; trackedThread.Thread.Start(); }
/// <summary> /// Erstellt einen neuen Controller, die Basisklasse für alle Komponenten der LaserControl Software. /// </summary> /// <param name="name">Name des Controllers</param> /// <param name="controlIdent">ControlIdent des Controller, sollte eindeutig im gesammten Programmsystem sein.</param> public Controller(string name, string controlIdent) { this.ControlIdent = controlIdent.ToUpper(); this.Name = name; EventThread1 = new TrackedThread(ControlIdent + " - EventThread 1", EventThread1Method); EventThread1.Start(); }
/// <summary> /// Starts the file download. /// </summary> /// <remarks> /// After a block has finished downloading, a new block will be requested for download. /// this will continue until no blocks are left, or told to stop. /// </remarks> public void Start() { Finished = false; TrackedThread thdDownloader = new TrackedThread(DoStart); thdDownloader.Thread.Name = String.Format("Block Dldr @ {0}", DateTime.Now); thdDownloader.Start(); }
private static void FlushThread(TrackedThread thread) { for (int i = 0; i < thread.Levels.Count; i++) { queuedLevels.Enqueue(thread.Levels[i]); } thread.Levels = new List <Level>(); }
/// <summary> /// Erstellt einen neuen IOController und initialisiert diesen. /// </summary> /// <param name="name">Name des Controllers</param> /// <param name="controlident">Eindeutiges zeichen des Controllers</param> public IOController(string name, string controlident) : base(name, controlident) { AllIOPorts = new List <IOPort>(); Load(); EventThread2 = new TrackedThread(ControlIdent + " - EventThread 2 (IO)", EventThread2Method); EventThread2.Start(); }
/// <summary> /// Erstellt eine neue Achse /// </summary> /// <param name="name"></param> /// <param name="controlident"></param> public Axis(string name, string controlident) : base(name, controlident) { this.Load(); IsMoving = false; EventThread2 = new TrackedThread(ControlIdent + " - EventThread 2 (Axis)", EventThread2Method); EventThread2.Start(); }
/// <summary> /// Uninstalls the mod. /// </summary> public void Install() { if (!ModInstallLog.ActiveMods.Contains(Mod)) { OnTaskSetCompleted(true, "The mod was successfully deactivated.", Mod); return; } TrackedThread thdWorker = new TrackedThread(RunTasks); thdWorker.Thread.IsBackground = false; thdWorker.Start(); }
private static void PlaceIndividual(Level level) { if (threads.Count == 0 || threads.Count < Environment.ProcessorCount) { threads.Add(new TrackedThread(level)); } else { TrackedThread lowestThread = threads[GetLowestStressThread()]; lowestThread.Stress += level.GetStress(); lowestThread.AddLevel(level); } }
public static void RunTest(MainWindow mw, HardwareController hwc) { #if TEST MW = mw; HWC = hwc; while (true) { TestWindow tw = new TestWindow(); if (tw.ShowDialog() != true) { continue; } int testNr = tw.SelectedTest.SelectedIndex; switch (testNr) { case 0: TrackedThread testThread = new TrackedThread("Test ImgButton", Test1); testThread.Start(); return; case 1: TrackedThread testThread2 = new TrackedThread("Test Enable Move Move Home Disable", Test2); testThread2.Start(); return; case 2: TrackedThread testThread3 = new TrackedThread("Test TabControl Main Window", Test3); testThread3.Thread.SetApartmentState(ApartmentState.STA); testThread3.Start(); return; case 3: TrackedThread testThread4 = new TrackedThread("Test Script with FAK", Test4); testThread4.Thread.SetApartmentState(ApartmentState.STA); testThread4.Start(); return; case 4: TrackedThread testThread5 = new TrackedThread("Test Script with FAK", Test5); testThread5.Thread.SetApartmentState(ApartmentState.STA); testThread5.Start(); return; default: MessageBox.Show("Unknown Test "); break; } } #endif }
/// <summary> /// Initializes the thread safe extractor. /// </summary> protected void Init() { m_queEvents = new Queue <ActionPackage>(); m_mreEvent = new ManualResetEvent(false); m_thdExtractor = new TrackedThread(RunThread); m_thdExtractor.Thread.IsBackground = false; m_thdExtractor.Thread.Name = "Seven Zip Extractor"; ActionPackage apkStart = new ActionPackage(null); m_queEvents.Enqueue(apkStart); m_thdExtractor.Start(); apkStart.DoneEvent.WaitOne(); }
static ScriptHandler() { EventThread = new TrackedThread("Script Handler State Event Thread", StateChangeEventThread); EventThread.Start(); Node.OnPaused += OnPaused; Thread_1 = new TrackedThread("Script Thread 1", Thread_1_Handle, true); //Thread_1.ApartmentState = ApartmentState.STA; Thread_1.Start(); Thread_2 = new TrackedThread("Script Thread 2", Thread_2_Handle, true); Thread_2.Start(); }
public AerotechCamera(string path) : base(path) { BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None); binding.MaxReceivedMessageSize = 2147483647; binding.MaxBufferSize = 2147483647; binding.MaxBufferPoolSize = 2147483647; EndpointAddress epa = new EndpointAddress(path); Client = new CameraServiceClient(binding, epa); UpdateThread = new TrackedThread("Camera " + Name + " Event Thread", UpdateThreadMethod); UpdateThread.Start(); }
public MainWindow() { Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US"); InitializeComponent(); Data = FindResource("datahandler") as MainWindowDataHandler; StartupInit(); ThreadUpdateMenu = new TrackedThread("MainWindow - Update Menu Bars", DisplayFileInfoAndUpdateMenuBars); ThreadUpdateMenu.Start(); ThreadUpdateStatusBar = new TrackedThread("MainWindow - Update Status Bar", DisplayStatusBarInformation); ThreadUpdateStatusBar.Start(); Data.StatusBarBackground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(0, 122, 204)); }
//CALLC("LaserControl.ScriptV2.ScriptHandler", "StopThread", 1); public static void StopThread(int i) { if (i == 1) { TrackedThread tt = new TrackedThread("Kill Script Thread 1", () => { StopThread1(); }); tt.Start(); } if (i == 2) { TrackedThread tt = new TrackedThread("Kill Script Thread 2", () => { StopThread2(); }); tt.Start(); } }
public CameraClickAndMove(HardwareController hwc) { InitializeComponent(); this.Progress.Maximum = TimeStepsMS; LoadValues(); Data = FindResource("datahandler") as CameraClickAndMoveDataHandler; HWC = hwc; //NewImage(); ImgThread = new TrackedThread("CameraClickAndMove Window New Image Thread", NewImageContinousShot); ImgThread.Start(); PreviousWindowState = System.Windows.WindowState.Normal; Console.WriteLine(this.GetType().AssemblyQualifiedName); }
public static void StopThread1() { if (State_1 != ScriptThreadState.Waiting) { try { Thread_1.Thread.Abort(); if (Thread_1_LocalNode != null) { Thread_1_LocalNode.Clean(); } if (Thread_1_Obj != null) { lock (Thread_1_Obj) { Thread_1_Obj.Clear(); Thread_1_Obj = null; } } GC.Collect(); GC.WaitForPendingFinalizers(); Thread_1 = new TrackedThread("Script Thread 1", Thread_1_Handle, true); Thread_1.Start(); //Reset pausing state Node.SetPaused(1, false); //Reset Line if there was a Event method connected if (Thread_1_LineChangeEvent != null) { Thread_1_LineChangeEvent(-1); } } catch { #warning Implement error handling } } }
protected void NewImage() { TrackedThread tt = new TrackedThread("New Image from Camera Thread", () => { Camera c = HWC.Camera; if (c.IsConnected) { Data.ImageVisible = System.Windows.Visibility.Collapsed; Data.ProgbarVisible = System.Windows.Visibility.Visible; TrackedThread localthread = new TrackedThread("New Image from Camera Thread (local)", () => { //c.SetOverlay(false, true, true); //c.SetProcessing(true); Thread.Sleep(TimeStepsMS); System.Drawing.Bitmap b = c.GetImage(); ContentImage.Dispatcher.Invoke(new Action(() => { Data.Img = BitmapToImageSource(b); })); b.Dispose(); Data.ImageVisible = System.Windows.Visibility.Visible; Data.ProgbarVisible = System.Windows.Visibility.Collapsed; }); localthread.Start(); for (int i = 0; i < TimeStepsMS; ++i) { Data.ProgbarValue = i; Thread.Sleep(1); } } }); tt.Start(); }
public static void Display(HardwareController hwc) { ScriptID = 0; if (HWC == null && hwc == null) { MessageBox.Show("Error while displaying Camera Window!"); return; } if (SingletonWindow == null) { if (System.Threading.Thread.CurrentThread.GetApartmentState() != ApartmentState.STA) { TrackedThread tt = new TrackedThread("Inner Thread,CameraClickAndMove.Display ", () => { SingletonWindow = new CameraClickAndMove(hwc); SingletonWindow.ShowDialog(); }); tt.ApartmentState = ApartmentState.STA; tt.Start(true); return; } SingletonWindow = new CameraClickAndMove(hwc); SingletonWindow.Show(); } else { if (SingletonWindow.Dispatcher.Thread != System.Threading.Thread.CurrentThread) { SingletonWindow.Dispatcher.Invoke(new Action(() => { CameraClickAndMove.Display(HWC); })); return; } SingletonWindow.WindowState = SingletonWindow.PreviousWindowState; SingletonWindow.ShowInTaskbar = true; } SingletonWindow.Data.ButtonsVisible = Visibility.Collapsed; }
/// <summary> /// A simple consturctor that initializes the object with the given values. /// </summary> /// <param name="p_strFilePath">The path of the file to which to write. If the /// file does not exist, is will be created.</param> /// <param name="p_strFileMetadataPath">The path of the file containing the metadata /// describing which parts of the file are already written.</param> public FileWriter(string p_strFilePath, string p_strFileMetadataPath) { m_strFilePath = p_strFilePath; m_strFileMetadataPath = p_strFileMetadataPath; if (File.Exists(p_strFileMetadataPath)) { string[] strRanges = File.ReadAllLines(p_strFileMetadataPath); foreach (string strRange in strRanges) { string strCleanRange = strRange.Trim().Trim('\0'); if (String.IsNullOrEmpty(strCleanRange)) { continue; } m_rgsWrittenRanges.AddRange(Range.Parse(strCleanRange)); } } m_thdWrite = new TrackedThread(WaitForData); m_thdWrite.Start(); }