Click here to Skip to main content
15,881,715 members
Everything / General Programming / Threads

Threads

threads

Great Reads

by Maxim Kartavenkov
Articles describes how to create virtual video capture source directshow filter in pure C#
by Maxim Kartavenkov
Article describes how to make H.264 Video Encoder DirectShow Filter using NVIDIA encoder API in C#
by Sergey Alexandrovich Kryukov
Addresses questions on graphics, threading with UI, form development, printing and more
by honey the codewitch
Take control of which thread your code gets executed on, and how it does

Latest Articles

by Bruno van Dooren
What to do when you want to use the current thread handle
by Bruno van Dooren
How to implement named pipe server for communicating with client apps
by Bruno van Dooren
How to implement named pipe server for communicating with client apps
by Greg Utas
Keeping a program running when it would otherwise abort

All Articles

Sort by Updated

Threads 

13 Jan 2010 by #realJSOP
Along with Rick's response, you can also create custom events that you can use to notify subscribed objects of the progress of important events within the thread. I use a thread pool, and custom events and it works great. I also would like to reiterate Rick's recommendation of the use of Invoke...
14 Mar 2010 by #realJSOP
First, you don't need the variable f - you'll see why in a moment.Second, your BackgroundWorker object should support cancellation so that it cleans up correctly if the user does something to dismiss the form while the worker is busy.The while statement should look something like...
3 May 2010 by #realJSOP
So accept the answer (there's a button there for it).
1 Sep 2010 by #realJSOP
Yes, you just have to be aware of the rules and the process involved. If you google that error message, you'll find all kinds of examples about how to do it.
1 Sep 2010 by #realJSOP
There are already two threads - the one the application is running on, and the one you started yourself. The BeginInvoke call simply does what .Net needs to have done in order to safely modify a control from a different thread. This topic is way to extensive to answer here because this part...
10 Dec 2010 by #realJSOP
You can display consecutive forms, allowing each one to live as long as it's needed and then close itself. I wrote a tip/trick about it:Multiple Subsequent "Main" Forms in C# Apps[^]
6 Jan 2011 by #realJSOP
You didn't mention what plaform/language, so I'm assuming C#.I think the best way to do this would be to pass the creating thread in as a parameter to the ThreadStart method of the child threads. You could make it simple by deriving a new class from the existing .Net Thread class and add a...
12 Jan 2011 by #realJSOP
The wyday blog says that using sendmessage/getmessage blocks the apps while the message is being processed. That's simply not true, sendmessage does - postmessage does not.He goes on to state that sendmessage/postmessage only allows intger values, that's true to some extent, but that integer...
20 Feb 2011 by #realJSOP
Maybe you could try putting the thread abort calls into the destructor of the custom control, or somehow hook the parent form's Closing event.
21 Feb 2011 by #realJSOP
0) You should use a thread pool so that your app doesn't bog down the system trying to process all of the files at the same time. 1) Stop using lamba expressions so that your code is easier to work on.2) I would do it this way:foreach (string file in fileEntries){ Thread t =...
22 Mar 2011 by #realJSOP
Why not just wait to validate the string until the user presses the enter key, and then make the validation part of the send thread processing? I think you're making it more difficult than it needs to be...
24 Mar 2011 by #realJSOP
You have to give us a little more info about your architecture. Is this in a desktop app? What database are you using? Is the code being inserted via a stored procedure? What does the schema look like? If your database is architected correctly, you shouldn't need to do anything *in your code*...
19 Apr 2011 by #realJSOP
I'm not sure about your design. Is the scanner multi-thread capable? Can multiple scanner objects access different devices at the same time?
21 Apr 2011 by #realJSOP
It's handled wherever you add a handler. The way you've done it is prefectly fine, if not a little obfuscatory (I prefer defined methods instead of that lambda stuff).
1 Sep 2011 by #realJSOP
Just out of curiosity, have you tried moving to .Net 4 and see if the behavior persists (just as a test)?
9 Sep 2011 by #realJSOP
We're not going to write the code for you. Try to implement it yourself and ask questions if you experience any problems. The best help I can give you right now is the URL for google:http://www.google.com[^]
30 Nov 2011 by #realJSOP
You could use the oft-ignored detructor and abort threads in the objects that created them. Of course, that's more like being a real programmer than most want to actully attempt.
24 May 2020 by #realJSOP
Have you considered setting up the property to fire a custom event when its value changes, and then have an event handler in the form that reacts to the event? No threads needed.
10 Nov 2011 by 01.mandar
http://connect...
6 Nov 2014 by 1337Architect
No, because when you do the Dispatcher.BeginInvoke you change thread to the UI thread. This means that while setting the slider value you are just running on one thread which would be the same as lock.
26 Dec 2014 by 28shivamsharma
Synchronized Blocks on object make that part thread-safe. Means Only one thread at a time can access that block. To access that block thread have to acquire lock then it can make operations & changes inside that block. In short it implements the mutual exclusion.
12 Aug 2012 by 3529255
I am using ThreadPool to make multiple calls to a method called RunScripts. Number of threads are maintained by a count of number of sql scriptfile to run. If there are 4 sqlscripts to run then I make call to ThreadPool.QueueUserWorkItem 4 times and son on. In the RunScripts method, I am using...
22 Apr 2010 by @Intersect☺™
Dear, pls do not post so lengthy code, unless that asked for. I guess most of the ppl got less interest after seeing long post. Try to describe your technical requirements & queries in quite understandable format, like:1. I want to create two FIFOs, bufA and bufB.2. bufA is filled by thrd1...
20 Oct 2018 by @k5hu
I came across these terms and I'm a bit confused about the differences. What I have tried: While searching for explanations I found few more terms like "Hold and Wait", "No preemption", "critical section" which made me more confused. Could anyone explain me the differences among Mutual...
27 Oct 2010 by @nuraGGupta@
hi everyone, In my application I need to collect the information of all the files in folder and send them to database.Since this is to be done for whole disk, this is a very time taking process. What I want to do is to create a seperate thread for each file in a folder and write each file...
10 Dec 2017 by ________________
One solution (simplest) - clients should have timer, and try to read from server messages every 1 second (or less, or more - according business demands). Second - each client should be also server for main, and when main will have message from one client, it should broadcast this message to...
18 Mar 2014 by _Asif_
Check these links might come handy for you.Task Parallelism (Task Parallel Library)[^]How to: Write a Simple Parallel.ForEach Loop[^]
1 Jul 2015 by _Asif_
A good reference point[^] on not touching priority of Thread PoolYou might find this link[^] interesting
10 Jul 2021 by aakar
We are calling a Rest API URL via the HttpWebRequest / HttpWebResponse method using IDs that are already stored in a database table. We am currently using a for each loop to iterate through each of the IDs fetched in a DataTable and then making a...
18 Apr 2013 by Aayman Khalid
Hey, I am new to the world of thread pools and I've been searching a lot about it but get confused in the mean process(due to a lot of advanced stuff)...at first I just want to get the hang of creating a thread pool and destroying it...could someone lay out the basic steps needed to...
18 Apr 2013 by Aayman Khalid
Hey, I am new to thread pools and well I wanted to start of by creating and destroying a thread pool first,I assume that's how we create a thread pool: PTP_POOL Pool = CreateThreadpool(NULL); if(Pool!=NULL) { ...
2 May 2013 by Aayman Khalid
I have to create an application where I'll have to make multiple threads. SoI thought to try making one function and passing it to different threads. Initially I've created two threads and have declared one function to be passed to both of them. All I am trying to do is to pass different...
28 Dec 2014 by Abdulmateen50
Hi, I am showing a loading window form in separate thread. My problem is when my task is over i am closing the window by calling Close() method but my main window is losing focus for getting focus back i need to select the form from the task bar.Here is my code : Thread thread = new...
1 Oct 2010 by Abhinav S
Cross thread communication is indeed possible.Have a look here[^] and here[^].
10 Jun 2011 by Abhinav S
You can include this task (program) in the Windows Scheduler.Or you can create a Windows Service to do this. Using a timer for this is not the best option.
14 Jan 2015 by Abhinav S
Use a timer - Observable.Timer Method [^].
13 Mar 2017 by abhiramthejas
cv::VideoCapture a; cv::VideoCapture b; cv::VideoCapture c; cv::VideoCapture d; a.open("traffic1.mp4"); b.open("traffic2.mp4"); c.open("traffic3.mp4"); d.open("traffic4.mp4"); std::thread t1 (traffic,a,"a"); std::thread t2 (traffic, b, "b"); std::thread t3(traffic, c,...
19 Dec 2012 by Abhishek Pant
Web Service and multiple requests from the same client[^]C# how to use timer in multi threading[^]
21 Jan 2013 by abhitechno
I have a network monitor program which continually monitors a list of ip addresses on the network and writes the log to a log file. The program works all right but after a few days of continuous running the UI hangs up and the task manager starts showing that my process is making too much CPU...
22 Jan 2013 by abhitechno
the problem lay elsewhere. the ui became unresponsive only when there was a unreachable node in the addresslist. this happened beacause my code was somewhat like thispublic void CheckIpAsync() { try { while (true) ...
21 May 2016 by Abtin Bina
i have an object that it have a 'Thread' property like this class Client{ public Thread ClientThread; // it is that i want to change //some property //some method }how can i set the ClientThread in a started threadlike what i have triedWhat I have...
2 Oct 2010 by adaapanya
Hello programmers. Sorry for my bad EnglishI would like to ask about thread. I created a program that uses thread. But I do not understand how to make the thread can sync with one another. Code like below:Imports System.ThreadingImports System.Runtime.CompilerServicesPublic Class...
2 Oct 2010 by adaapanya
Thanks Nicholas, you gave me the solutionHere is the right code for Class Scrambler :Public Class Scrambler Public rnd As New Random Public _Number As Integer Public ThreadWorker As New Thread(AddressOf Random) Public _Left As Integer Public _Top As Integer ...
19 Dec 2012 by Adam R Harris
You are going to have to create a delegate to add the controls for you, something like this:** assuming your flow control is called 'flow' private delegate sub delAddControl(ctrl as Control) private sub AddControl(ctrl as Control) if (flow.InvokeRequired) then ...
3 Dec 2009 by Adam Robinson
The ProcessQueue manages a pool of threads to process a strongly-typed queue of items.
17 Feb 2014 by Adarsh Chaurasia - Passionate Trainer
Here I will discuss the concepts of threading / multi-threading in C# using program.
27 Dec 2021 by Admin BTA
So I have an event that does some processing and one of the lines in the event takes a long time to complete thus the stuff that happens in the event, very undesireably. Is it common practice to separate out the thing that takes long (in this...
25 Sep 2012 by Adwaitam
I have a long running process called as the balancing process. This process updates the records in the database.I have 2 radio buttons1: Show all records2: Show only imbalancesThese radio buttons are used to fetch the data fromt he database and display them on my web page. The 2nd...
17 Apr 2012 by Aescleal
How about sending the data as part of the message you post to the UI? Especially as it's only one word of information:LRESULT CContactFault::OnDeviceShortAddress(WPARAM, LPARAM lparam){ UINT data = reinterpret_cast(lparam); CsLoader = _T("%d"); CsTmp.Format(CsLoader,...
23 Mar 2013 by AfnanMof
Steps How to Develop Sharepoint Windows Forms
20 Nov 2013 by agent_kruger
try chk.BringToFront();
2 Jun 2020 by agent_kruger
How to kill a working thread properly. I tried Thread.Abort();And Thread.Interrupt();Thread.Abort();but none of this work. Any suggestion where i am going wrong will be helpful.
25 Dec 2013 by AghaKhan
I have a store application where I am using a control from DLL (Based on Window Runtime component). My all View Models are in that DLL. In that DLL there is timer which updates the view (UI) and get exception "Called from different thread". I am not sure how to resolve this proble.
26 Dec 2013 by AghaKhan
private CoreDispatcher _dispatcher = null; public event PropertyChangedEventHandler PropertyChanged; private async Task UIThreadAction(Action act) { await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => act.Invoke()); } ...
6 Mar 2013 by Ahmed Elkafrawy
An easy way to simulate keyboard press & release keys to another application
19 Oct 2012 by ahp-1984
Hi Team, I have a methods which is used to create the JSON(.txt) file average size of file is arounnd 1.70 Mb to 2.0 mb,this method is is taking 3 to 4 minutes of time to create single file as the data is coming from multiple tables.if i run it for 10 to 15 files its generated but...
23 Apr 2010 by Ajay Vijayvargiya
Hope these articles would help you:The Practical Guide to Multithreading - Part 1[^]The Practical Guide to Multithreading - Part 2[^]
10 Jan 2011 by Ajay Vijayvargiya
24 Feb 2018 by Akhil Jain
This is my code in which a list contains 2 more lists where the WorkItem collection contains a large number of records such as 7,000 it takes 10 min. Is there any way to make it faster and in case it's deciding the workItem type if it's a bug, task or product backlog item. Please tell me how to...
3 Aug 2011 by Akshatha.A
Hi, I have one button and when the button.text equals "start" I am calling my method startThread() where a thread is started. Otherwise my mehtod stopthread() gets called where I set a boolean variable to false. This scenario only works once. If I click start again the following error is...
12 Feb 2018 by Akshit Gupta
I have a code for thread execution in Java.. But the threads are not working concurrently.. Here is the code.. class Abc { public static void main(String[] ar){ Mythread mt = new Mythread(); mt.start(); Mythread mt1 = new Mythread(); ...
4 Feb 2016 by Al_Brown
As an alternative to using a background worker you can use BeginInvoke to ensure the text is changed on the main user interface thread.This CodeProject article gives a very good overview and has a code example doing almost exactly what you need to fix your sample code.
1 Sep 2010 by Alan N
Think of Control.BeginInvoke as a queueing mechanism. It adds the delegate to a job queue which will be executed at some point in the future by the thread that owns the control's handle.The explanation in the link may help.http://www.drdobbs.com/184429353[^]Alan.
13 Oct 2012 by Alan N
I was looking into this yesterday when I had a similar problem. If you open the published source code Timer.cs[^] and scroll down to the MyTimerCallback method you'll see that the event invocation has an empty catch block.Although I had never noticed it before, the behaviour is documented...
11 Jan 2014 by Alan N
Hi Jayanta,I was reading the discussion you were having with OriginalGriff and I wonder if the real problem is the poor performance of Microsoft's TableLayoutPanel. If you are having issues with redraw then enabling double buffering on the control will speed it up. I have found that on .NET...
26 Jun 2014 by Alan N
There is a simple mistake in the code.What it should do1) read serial port on the background thread2) update the textbox on the UI threadWhat the code actually does1) read serial port on the UI thread2) update the textbox on the UI threadIf you separate the reading part from...
9 Jan 2013 by Albara Hakami
A Windows Forms application to share a whiteboard with many clients with only one drawer, in a gamy way.
17 Jun 2011 by Albert Holguin
I would say its perfectly fine to do so... I've had to create manager classes that start multiple threads and the constructor is where it makes most sense to do so. In a lot of cases, if your thread fails to start, you're going to end the application anyway.
3 Jul 2011 by Albert Holguin
Check to see if there's any errors being returned from the Create() method when you try to create the dialog. There may also be an issue with creating a modeless dialog on a thread that just ends right after creating the dialog.
20 Mar 2013 by Albert Holguin
Solution 2 is great... but why not just use the new threading that is in C++11? It will be standardized and supported across every platform that you can think of and most new compilers already support it (new gcc and vc compilers already support it). Usually it's a lot better to use something...
28 Oct 2014 by Albert Holguin
Just from a short read through your description the first thing I'd suggest is NOT to use global variables when multi-threading. When you start a new thread one of the things you can pass to it is a pointer to a structure. This structure should contain all of the thread instance variables that...
28 Dec 2015 by Albert Holguin
Your question isn't clear because you'll always be in a "thread" regardless of whether you started the thread explicitly or not. Given your code, I'm guessing your question is because you're just starting to learn about multithreading. I'm going to guess you mean, "can I execute other code...
14 Feb 2011 by Albin Abel
I am having an example here. say in this example MyBusyObject class has the business logic. Follow the example. Ask me if any doubt arisesIn the business logic code (in class files)...public interface IObservable{ void notify();}public interface IObserver{ void...
15 Apr 2011 by Albin Abel
Here is an example code.public class ThreadTest{ private string _file="Hello World"; private ReaderWriterLock _rw1=new ReaderWriterLock(); public void ReadFile(object obj) { _rw1.AcquireReaderLock(1000); for(int i=0;i
15 Apr 2011 by Albin Abel
15 Jan 2013 by Alessandro Lentini
How to write a simple multi-thread queue for the typical producer-consumer process
2 Sep 2011 by Alexander Bessonov
A simple high-level IPC library with ability to use native C++ interfaces.
23 Jan 2014 by Alexander Sharykin
Implementations of a computing pipeline, with design explanation and code samples
6 Jun 2012 by ali.hnd
Hihow to know when a work in a thread is complete?Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Dim firstThread As New Thread(AddressOf Fu1) firstThread.Start()'I want to determine the job of sub (Fun) is finished and...
8 Jun 2012 by ali.hnd
Dim firstThread As New Thread(AddressOf Job1)Dim SecondThread As New Thread(AddressOf Job2)Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click firstThread.Start() SecondThread.Start()End SubSub...
7 May 2015 by ali_heidari_
Hello.I want to give multi threading ability to a javascript prototype. I mean i have a funtion in my object ,when i call it, it generates a thread or better to say web worker. basic things done, but when i receive message from web worker, I cant access 'this' variable that refers to current...
12 Sep 2015 by alireza ghasemi
Hi everybodyI am an minerals engineer. I am programming a code for simulating a kind of system. the whole program contains a infinite loop and it will be stopped when I exit my program. In my codes, I am using 3 threads right now. The fist thread just displaying the simulation results, the...
2 Feb 2011 by All Time Programming
Hello,In my app, I read/parse data that takes some time. While that process is going on I want to display a message on screen indicating the process going on. I beileve I got to use Thread for it, but don't get an idea how to use and implement it.The calling method may throw exception or...
8 Feb 2011 by All Time Programming
Hello, I have a dialog (WaitingDialog) that is mainly used to display the happening activities. It has a Title & Message that sets the respective labels.public string Title { get { return title; } set { title = value; label1.Text = title; }}public string...
27 Feb 2011 by All Time Programming
Hello, I have a Winform app that has a backgroundWorker thread and does all operations via that only. After completing one particular operation i.e. to connect to the server, I want to create a monitor to check the connectivity with the server is alive or not. A web service will be...
1 Jun 2011 by All Time Programming
Hello, In my mainForm I have a BackgroundWorker. I call a WaitDialog when the task for bgworker is started and close it when completed. I want to have a Cancel button in WaitDialog and when clicked, notify the bgworker task to cancel the task. This is how I call and show my waitDlg in...
14 Jun 2011 by All Time Programming
Hello, My C# application contains a BackgroundThread. I am on a stage that on an event I got to call a method (that Runs bgworker) untill the process is successful. And if an error is occured then stop the loop. public void DisconnectEvent() { ...... // START THE ...
14 Jun 2011 by All Time Programming
Hi to All, This is the solution if at all it might be helpful for any :I didn't extend any class to MonitorConnection.Added a event in MonitorConnection that fires when the connection is lost (after starting the monitor) and is handled in main application.This way I got control of...
16 Jun 2011 by All Time Programming
Hello, I have a backgrounworker thread that calls a method (Connect()). When that process is completed it comes to RunCompleted where I check it its connectedToServer or not. I not, I call a method (CallToReconnect()). Over here, I got to wait for 20 secs updating the status bar on each...
16 Jun 2011 by All Time Programming
SA, then by using Thread.Sleep, how do I update the text in statusbar as wanted ? I am not able to handle that part as expected hence tried with timer.Do you have any idea to avoid timer, use Thread.Sleep & update the text every sec ?
1 Sep 2013 by AlwaysLearningNewStuff
I have a dialog box with a Save button.When that button is clicked, I should populate excel with data from database.To do that, I have modified code from here: http://support.microsoft.com/kb/216686[^], which suites my purposes .The problem is that this operation is lengthy and...
26 Jan 2014 by AlwaysLearningNewStuff
INTRODUCTION AND RELEVANT INFORMATION:I have a main window with a button.On button click a dialog box is shown.Dialog box has a button that spawns a thread.Thread function communicates with the dialog box via 2 custom messages.Right now I am using a boolean variable the way...
27 Aug 2012 by Ami Bar
A .NET Thread Pool fully implemented in C# with many features.
17 Mar 2014 by Ami_Modi
Hello everybody,I have a console application from where I have to send mails and have to retrieve statistics about mail from third party at every 5 minutes. As I have to send more number of mails and it may take 4-5 hours, i can not wait to get it over and than start getting statistics. So I...
27 Apr 2014 by Ami_Modi
I am writing mail sending script. In main thread the data is brought from database and mail is sent and as the mail sending starts few changes are made in database like sending_status become 'Sending' etc.I have used timer thread where every 5 mins a function is called and database is...
10 Mar 2011 by Amit kumar pathak
I want to read the MSMQ where queue data in byte and numbers of queues generated in 1 mins about 1500.If read continuously queue, cpu goes on 30%, and after some time it stopped. I need to read queue in high volume upto 4 hrs.I want safe thread reading in such a manner that shouldn't...
18 Mar 2011 by Amit kumar pathak
I am reading data in bytes on one UDP client port which is broadcast by other server. I have created a single thread with sleep time it works when data incoming is slow but when data incoming incresaes then its memory use go high and terminate with unknown error.I want help on this like...
30 Jul 2012 by amit.kailas.sawji
I want to host a WCF on a separate thread. There will be a windows application which will communicate with this WCF. The WCF will be hosted inside this windows application and UI thread of this windows application will communicate with this WCF hosted in a worker thread.WCF will be a duplex...