multithreading

Closing form from another thread

会有一股神秘感。 提交于 2020-04-09 15:46:42
问题 I have got this code which runs an .exe string openEXE = @"C:\Users\marek\Documents\Visual Studio 2012\Projects\tours\tours\bin\Debug\netpokl.exe"; Process b = Process.Start(openEXE); b.EnableRaisingEvents = true; b.Exited += (netpokl_Closed); And when it closes it calls method netpokl_Closed. The issue is when I insert into netpokl_Closed command - this.Close() this exception rises: Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on How

Closing form from another thread

只愿长相守 提交于 2020-04-09 15:46:41
问题 I have got this code which runs an .exe string openEXE = @"C:\Users\marek\Documents\Visual Studio 2012\Projects\tours\tours\bin\Debug\netpokl.exe"; Process b = Process.Start(openEXE); b.EnableRaisingEvents = true; b.Exited += (netpokl_Closed); And when it closes it calls method netpokl_Closed. The issue is when I insert into netpokl_Closed command - this.Close() this exception rises: Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on How

Object not locked by thread before notify() in onPostExecute

六眼飞鱼酱① 提交于 2020-04-08 18:37:09
问题 I try to notify adapters of listviews of main class in onPostExecute but I receive the error: java.lang.IllegalMonitorStateException:object not locked by thread before notify() @Override protected void onPostExecute(String result) { popularfragment.adapter.notifyDataSetChanged(); recentfragment.adapter.notifyDataSetChanged(); } 回答1: The .notify() method has to be called from within a synchronized context, ie from inside a synchronized block. The java.lang.IllegalMonitorStateException is

How to sleep PHP(Laravel 5.2) in background

好久不见. 提交于 2020-04-08 17:57:45
问题 I have created an artisan command that I want to run immediately after a method called. But the command contains a sleep(); command. I want to run that artisan command in background because the method need to return immediately response to user. My sample code is a below: In route file Route::get('test', function(){ Artisan::queue('close:bidding', ['applicationId' => 1]); return 'called close:bidding'; }); In close:bidding command public function handle() { $appId = $this->argument(

Events and multithreading once again

岁酱吖の 提交于 2020-04-07 16:11:10
问题 I'm worried about the correctness of the seemingly-standard pre-C#6 pattern for firing an event: EventHandler localCopy = SomeEvent; if (localCopy != null) localCopy(this, args); I've read Eric Lippert's Events and races and know that there is a remaining issue of calling a stale event handler, but my worry is whether the compiler/JITter is allowed to optimize away the local copy, effectively rewriting the code as if (SomeEvent != null) SomeEvent(this, args); with possible

how multiple threads invoke singleton object's method and work on them?

自闭症网瘾萝莉.ら 提交于 2020-04-07 10:57:30
问题 I have multiple threads running which access singleton object and call its method and pass objects in it. In the method I do some calculations only on recieved object. I have heard that there would not be any problem in this case cause it is stateless and it is free for all. My question is how it is free for all? I want to know how multiple threads can call the shared method in their own thread without overwriting the passed objects of other threads? Please explain in terms of memory

Java Wait and Notify: IllegalMonitorStateException

梦想与她 提交于 2020-04-07 08:33:05
问题 I don't completely understand how wait and notify (of Object ) work, and as a result I'm forced to slim down my attempts into the following section of code. Main.java: import java.util.ArrayList; class Main { public static Main main = null; public static int numRunners = 4; public static ArrayList<Runner> runners = null; public static void main(String[] args) { main = new Main(); } Main() { runners = new ArrayList<Runner>(numRunners); for (int i = 0; i < numRunners; i++) { Runner r = new

C# Parallel.ForEach() memory usage keeps growing

让人想犯罪 __ 提交于 2020-04-07 08:11:47
问题 public string SavePath { get; set; } = @"I:\files\"; public void DownloadList(List<string> list) { var rest = ExcludeDownloaded(list); var result = Parallel.ForEach(rest, link=> { Download(link); }); } private void Download(string link) { using(var net = new System.Net.WebClient()) { var data = net.DownloadData(link); var fileName = code to generate unique fileName; if (File.Exists(fileName)) return; File.WriteAllBytes(fileName, data); } } var downloader = new DownloaderService(); var links =

Memory lock to ensure shared data can be read from by many threads, but only written to by one?

烂漫一生 提交于 2020-04-07 05:38:18
问题 I am trying to write a C# program where values in a list A are checked against a particular value x in a thread. I would like the threads to compare their x values to each of the ones in the list, and if it is not found, I would like them to add their value x to A . The thread will then get a new x from a list in it's private memory, and begin comparing it to the values in A again. The objective of this program is to make A a list of unique values, and contain all of the values of the lists

How do I start one thread for my code and one for a JavaFX Application?

柔情痞子 提交于 2020-04-07 05:18:18
问题 I'm trying to run a program using JavaFX. If I was using Swing, I would have one class started by the main method, and have it build the GUI class. That would give me 2 threads, normal thread for an application, and the EventQueue. That would prevent blocking the UI work. So, I tried to have the class created in the static main method construct the Application class, and then launch it. I got a RuntimeException because the program calling the launch method was not a subclass of Application.