473,387 Members | 1,532 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Stop and run thread from some place

This is my code. The bold part says something about an invalid thread state. How to stop and run the thread from private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e) ?

Expand|Select|Wrap|Line Numbers
  1. using ....
  2.  
  3. namespace ns
  4. {
  5.     public partial class MainWindow : Window
  6.     {
  7.         public MainWindow()
  8.         {
  9.             InitializeComponent();
  10.         }
  11.  
  12.         public Thread stre;
  13.  
  14.         private void Window_Loaded(object sender, RoutedEventArgs e)
  15.         {
  16.            // run test()
  17.         }
  18.  
  19.         void test()
  20.         {
  21.             stre = new Thread(unused => threadname(content));
  22.             stre.Start();
  23.         }
  24.  
  25.         void threadname(content content)
  26.         {
  27.  
  28.         }
  29.  
  30.         private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
  31.         {
  32.             if (stre != null)
  33.             {
  34.                 stre.Abort();
  35.             }
  36.             stre.Start();
  37.         }
  38.     }
  39. }
  40.  
  41.  
Mar 16 '12 #1
0 1463

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: andrewcw | last post by:
I have an external VB6 app that I call in a loop. Because the process is long, I would like to be able to terminate the spawned thread & the VB6 application. My current loop calls a this...
4
by: Osvaldo Bisignano | last post by:
When I press a button, I start a new Exe file as a new Thread. When the mainform of that exe closes, i thought the thread was over. When and How shoud i terminate the subprocess?
7
by: Morris | last post by:
I want to abort a running thread, so I call MyThread.abort() function. My problem is this thread runs "almost" like a while(true) loop and I don't want the Abort() function interrupts the thread at...
3
by: Ha ha | last post by:
I create a main thread ,than create a subthread in the main thread,when i found any error,i want to stop the subthread and the main thread immediatly .How can i do for it. *** Sent via...
1
by: magic man via .NET 247 | last post by:
hi everyone i have a c# application that uses multithreading toconnect to sql server and execute a stored procedure on theserver. i am using a dataset,sqlcommand,dataadapter and adatagrid to carry...
6
by: Tomaz Koritnik | last post by:
I have a class that runs one of it's method in another thread. I use Thread object to do this and inside ThreadMethod I have an infinite loop: While (true) { // do something Thread.Sleep(100);...
1
by: scorpion53061 | last post by:
I have MS Word operating in a thread other than the main writing a report. Can I tell the main thread to wait until a particular point (a sub starts) in another thread before continuing on?
2
by: many_years_after | last post by:
Hi,pythoners: I countered some problems when I try to stop threads using flag. These are my some important codes: ##### mythread.py def run(self): while self.addr != '': ### text waiting...
4
by: Giulio Petrucci | last post by:
Hi there, I have two threads: - thread A: write some data into a stream (audio on an audio card,...etc...) - thread B: listen for an event (mouse click,...) I need to stop A when the event B's...
3
by: yeye.yang | last post by:
hey everybody Does everybody can help me or give me some advise for the cross thread exception catch Here is what I want to do: I have 2 classes "Scenario" and "Step", which have a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.