multithreading

Using Object.wait(millisec) to simulate sleep

Here's a snippet of code that I saw in some code I'm maintaining. Object lock = new Object(); synchronized( lock ) { try { lock.wait( 50000 ); Thread.sleep( 3000 ); } catch(Exception ex) { } } The developer wants to suspend the current thread for some amount of time and is using Object#wait as the me...

closing main from another thread

I am trying to close the appliaction some how when another thread finishes. I am using c#. code below is just an example class main { constuctor { thread t = new thread(open loading screen); } public void open loading screen() { if (error) exit program application.exit(); // doesn't work this.Close; ...

Accessing UI in a thread

When i try to change a UI property (specifically enable) my thread throws System.Threading.ThreadAbortException How do i access UI in a Thread. ...

control event - question about thread

Hi Language: C# (WinForms) There is one think I don't fully understand: Suppose I have normal button.Click event. I know for sure from my own experience that if I try to access UI elements from inside of this event I could potentially got unwanted behavior - or even exception (when debugging). The usual exception in such a scenario is...

How to read textbox.Text value from another thread in WPF?

In my WPF form I have a textbox. When a timer elapses, the content of the textbox needs to be fetched. The timer elapsed is working in a different thread then the UI. The question is kinda two-fold: What is the easiest, most readable way to read the value from a GUI thread cross thread (I found several and they look too verbose for wh...

Timeout Pattern - How bad is Thread.Abort really?

I've read at various websites that Thread.Abort is not very good to use. In this case, how do you implement a timeout pattern? For instance, I've read that MS uses the pattern below (which I've wrapped in an extension method) throughout the framework. Personally, I think this is a pretty cool extension, but I'm worried about the Thread.A...

ContainsKey Thread Safe

In the following code: public class StringCache { private readonly object lockobj = new object(); private readonly Dictionary<int, string> cache = new Dictionary<int, string>(); public string GetMemberInfo(int key) { if (cache.ContainsKey(key)) return cache[key]; lock (lockobj) { ...

C# WebBrowser control not firing the DocumentCompleted event

I have a program that is using the C# WebBrowser control and it needs to detect which page is loaded to determine what to do next. The program works fine on most of the employee's computers at the office, but it does not work on some. I have determined the problem is that the documentCompleted event is not firing on those computers it ...

What is some advice for debugging really hard to track down bugs?

Most bugs are fairly simple, easily reproducible, and easy to debug. What do you do when you run into ones that are hard or impossible to repro under debugger, i.e.one of these? Our app is a multi-threaded app that is furthermore complicated by the fact that it communicates with multiple clients via remoting and sometimes there're bugs...

C# Synchronize two objects through events

I have 2 objects. Foo and Bar in two different threads. Now I want to rais an event in Foo but in the thread of Bar. and how can I use SynchronizationContext.Current for that? ...

Need help to decide what is the best solution to tracking system (.NET)

Hello people ! That is my first question around here, my name is Anna! My problem: My client has several personal devices (blackbox with gps) to locate people/car... There are about 12000 people/car using that device... It sends their location to specified IP/Port... I can´t do anything on that side... My job? Devolope a listener to ca...

How can I connect to a database on a remote server in a background thread?

I have a windows form, on which I display data from a local database. I'd like to also connect to a remote database, and display some other data from there.. however, this remote database could be down, or slow. I don't want the UI to freeze while I try to connect to this remote database. So knowing nothing about threading or thread-...

Thread needs to be run continuously even exception occurs in it

Hi, My application uses a thread which should be running continuously. If any exception it should log that exception and should not stop. currently my code is like below. Can any one help me? void methodname() { try { while(1) executable statements } catch { log exception } } ...

WMEncoder randomly dereferences during execution

I have a program that converts lots of audio using WMEncoder. Sometimes during execution I get the following error: System.Runtime.InteropServices.COMException] Retrieving the COM class factory for component with CLSID {632B606A-BBC6-11D2-A329-006097C4E476} failed due to the following error: 80040154. WMEncoder is installed and some fi...

Why is this code executing faster than expected?

I have this code: public void replay() { long previous = DateTime.Now.Ticks; for (int i = 0; i < 1000; i++) { Thread.Sleep(300); long cur = DateTime.Now.Ticks; Console.WriteLine(cur - previous); previous = cur; } } Which is invoked as a separate thread lik...

Is a Java socket's PrintWriter thread safe?

So, I have two threads. Thread one manages the client connections. (There is only one client and one server) I call it my server thread. Thread two manages sending messages to the client. I call it my message processor thread. Thread one is responsible, among other things sending a heartbeat to the client periodically. When progr...

Threads in x86 assembler (using the GNU assember: as)

Whilst learning the "assembler language" (in linux on a x86 architecture using the GNU as assembler), one of the aha moments was the possibility of using system calls. These system calls come in very handy and are sometimes even necessary as your program runs in user-space. However system calls are rather expensive in terms of performanc...

Java: synchronizing threads across multiple servers

I have a problem where I need to synchronize processing for multiple threads across multiple different servers for a Java service on Windows. In this application, I have multiple consumer threads pullings messages off the same JMS queue. Messages come in in groups of 3 or 4, and I need to make sure the messages in each group are proces...

When to use asynchronous operations in asio

When should I use asynchronous operations in boost::asio instead of synchronous operations in seperate threads? ...

Accessing Class members with Invoke from a different thread in C#

Note: Part of a series: C#: Accessing form members from another class and How to access form objects from another cs file in C#. Hello, The Idea is to notify the user using the memo when a packet is received/sent in a TCP Client. After couple of fixes,the most suitable solution seemed to be this one public string TextValue ...