Search Results

Search found 8588 results on 344 pages for 'thread abort'.

Page 93/344 | < Previous Page | 89 90 91 92 93 94 95 96 97 98 99 100  | Next Page >

  • NSDrawer delegate pointing to deallocated object?

    - by Isaac
    A user has sent in a crash report with the stack trace listed below (I have not been able to reproduce the crash myself, but every other crash this user has reported has been a valid bug, even when I couldn't reproduce the effect). The application is a reference-counted Objective-C/Cocoa app. If I am interpreting it correctly, the crash is caused by attempting to send a drawerDidOpen: message to a deallocated object. The only object that should be receiving drawerDidOpen: is the drawer's delegate object (nowhere does any object register to receive drawer notifications), and the drawer's delegate object is instantiated via the XIB/NIB file, wired to the delegate outlet of the drawer, and not referenced anywhere else. Given that, how can I protect against the delegate getting dealloc'd before the drawer notification? Or, alternately, what have I misinterpreted that might be causing the crash? Crash log/stack trace: Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000010 Crashed Thread: 0 Dispatch queue: com.apple.main-thread Application Specific Information: objc_msgSend() selector name: drawerDidOpen: Thread 0 Crashed: Dispatch queue: com.apple.main-thread 0 libobjc.A.dylib 0x00007fff8272011c objc_msgSend + 40 1 com.apple.Foundation 0x00007fff87d0786e _nsnote_callback + 167 2 com.apple.CoreFoundation 0x00007fff831bcaea __CFXNotificationPost + 954 3 com.apple.CoreFoundation 0x00007fff831a9098 _CFXNotificationPostNotification + 200 4 com.apple.Foundation 0x00007fff87cfe7d8 -[NSNotificationCenter postNotificationName:object:userInfo:] + 101 5 com.apple.AppKit 0x00007fff8512e944 _NSDrawerObserverCallBack + 840 6 com.apple.CoreFoundation 0x00007fff831d40d7 __CFRunLoopDoObservers + 519 7 com.apple.CoreFoundation 0x00007fff831af8c4 CFRunLoopRunSpecific + 548 8 com.apple.HIToolbox 0x00007fff839b8ada RunCurrentEventLoopInMode + 333 9 com.apple.HIToolbox 0x00007fff839b883d ReceiveNextEventCommon + 148 10 com.apple.HIToolbox 0x00007fff839b8798 BlockUntilNextEventMatchingListInMode + 59 11 com.apple.AppKit 0x00007fff84de8a2a _DPSNextEvent + 708 12 com.apple.AppKit 0x00007fff84de8379 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 155 13 com.apple.AppKit 0x00007fff84dae05b -[NSApplication run] + 395 14 com.apple.AppKit 0x00007fff84da6d7c NSApplicationMain + 364 15 (my app's identifier) 0x0000000100001188 start + 52

    Read the article

  • Logging to a file on Android

    - by Greg B
    Is there any way of retrieving log messages from an Android handset. I'm building an application which uses the GPS of my HTC Hero. I can run and debug the application from eclipse but this isn't a good use case of GPS, sat at my desk. When I fire the app up when I am walking around, I get an intermittent exception. Is there anyway I can output these exceptions to a text file on the SD card or output calls to Log.x("") to a text file so that I can see what the exception is. Thanks EDIT : Solution Here is the code I finally went with... Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread thread, Throwable ex) { PrintWriter pw; try { pw = new PrintWriter( new FileWriter(Environment.getExternalStorageDirectory()+"/rt.log", true)); ex.printStackTrace(pw); pw.flush(); pw.close(); } catch (IOException e) { e.printStackTrace(); } } }); I had to wrap the line pw = new PrintWriter(new FileWriter(Environment.getExternalStorageDirectory()+"/rt.log", true)); in a try/catch as Eclipse would not let me compile the app. It kept saying Unhandled exception type IOException 1 quick fix Sorround with try/catch So I did and it all works which is fine by me but it does make me wonder what Eclipse was on about...

    Read the article

  • How can I keep an event from being delivered to the GUI until my code finished running?

    - by Frerich Raabe
    I installed a global mouse hook function like this: mouseEventHook = ::SetWindowsHookEx( WH_MOUSE_LL, mouseEventHookFn, thisModule, 0 ); The hook function looks like this: RESULT CALLBACK mouseEventHookFn( int code, WPARAM wParam, LPARAM lParam ) { if ( code == HC_ACTION ) { PMSLLHOOKSTRUCT mi = (PMSLLHOOKSTRUCT)lParam; // .. do interesting stuff .. } return ::CallNextHookEx( mouseEventHook, code, wParam, lParam ); } Now, my problem is that I cannot control how long the 'do interesting stuff' part takes exactly. In particular, it might take longer than the LowLevelHooksTimeout defined in the Windows registry. This means that, at least on Windows XP, the system no longer delivers mouse events to my hook function. I'd like to avoid this, but at the same time I need the 'do interesting stuff' part to happen before the target GUI receives the event. I attempted to solve this by doing the 'interesting stuff' work in a separate thread so that the mouseEventHookFn above can post a message to the worker thread and then do a return 1; immediately (which ends the hook function but avoids that the event is handed to the GUI). The idea was that the worker thread, when finished, performs the CallNextHookEx call itself. However, this causes a crash inside of CallNextHookEx (in fact, the crash occurs inside an internal function called PhkNextValid. I assume it's not safe to call CallNextHookEx from outside a hook function, is this true? If so, does anybody else know how I can run code (which needs to interact with the GUI thread of an application) before the GUI receives the event and avoid that my hook function blocks too long?

    Read the article

  • Search a string in a file and write the matched lines to another file in Java

    - by Geeta
    For searching a string in a file and writing the lines with matched string to another file it takes 15 - 20 mins for a single zip file of 70MB(compressed state). Is there any ways to minimise it. my source code: getting Zip file entries zipFile = new ZipFile(source_file_name); entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = (ZipEntry)entries.nextElement(); if (entry.isDirectory()) { continue; } searchString(Thread.currentThread(),entry.getName(), new BufferedInputStream (zipFile.getInputStream(entry)), Out_File, search_string, stats); } zipFile.close(); Searching String public void searchString(Thread CThread, String Source_File, BufferedInputStream in, File outfile, String search, String stats) throws IOException { int count = 0; int countw = 0; int countl = 0; String s; String[] str; BufferedReader br2 = new BufferedReader(new InputStreamReader(in)); System.out.println(CThread.currentThread()); while ((s = br2.readLine()) != null) { str = s.split(search); count = str.length - 1; countw += count; //word count if (s.contains(search)) { countl++; //line count WriteFile(CThread,s, outfile.toString(), search); } } br2.close(); in.close(); } -------------------------------------------------------------------------------- public void WriteFile(Thread CThread,String line, String out, String search) throws IOException { BufferedWriter bufferedWriter = null; System.out.println("writre thread"+CThread.currentThread()); bufferedWriter = new BufferedWriter(new FileWriter(out, true)); bufferedWriter.write(line); bufferedWriter.newLine(); bufferedWriter.flush(); } Please help me. Its really taking 40 mins for 10 files using threads and 15 - 20 mins for a single file of 70MB after being compressed. Any ways to minimise the time.

    Read the article

  • Making a database backup to SDCard on Android

    - by Pentium10
    I am using the below code to write a backup copy to SDCard and I get java.io.IOException: Parent directory of file is not writable: /sdcard/mydbfile.db private class ExportDatabaseFileTask extends AsyncTask<String, Void, Boolean> { private final ProgressDialog dialog = new ProgressDialog(ctx); // can use UI thread here protected void onPreExecute() { this.dialog.setMessage("Exporting database..."); this.dialog.show(); } // automatically done on worker thread (separate from UI thread) protected Boolean doInBackground(final String... args) { File dbFile = new File(Environment.getDataDirectory() + "/data/com.mypkg/databases/mydbfile.db"); File exportDir = new File(Environment.getExternalStorageDirectory(), ""); if (!exportDir.exists()) { exportDir.mkdirs(); } File file = new File(exportDir, dbFile.getName()); try { file.createNewFile(); this.copyFile(dbFile, file); return true; } catch (IOException e) { Log.e("mypck", e.getMessage(), e); return false; } } // can use UI thread here protected void onPostExecute(final Boolean success) { if (this.dialog.isShowing()) { this.dialog.dismiss(); } if (success) { Toast.makeText(ctx, "Export successful!", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(ctx, "Export failed", Toast.LENGTH_SHORT).show(); } } void copyFile(File src, File dst) throws IOException { FileChannel inChannel = new FileInputStream(src).getChannel(); FileChannel outChannel = new FileOutputStream(dst).getChannel(); try { inChannel.transferTo(0, inChannel.size(), outChannel); } finally { if (inChannel != null) inChannel.close(); if (outChannel != null) outChannel.close(); } } }

    Read the article

  • Threading calls to web service in a web service - (.net 2.0)

    - by Ryan Ternier
    Got a question regarding best practices for doing parallel web service calls, in a web service. Our portal will get a message, split that message into 2 messages, and then do 2 calls to our broker. These need to be on separate threads to lower the timeout. One solution is to do something similar to (pseudo code): XmlNode DNode = GetaGetDemoNodeSomehow(); XmlNode ENode = GetAGetElNodeSomehow(); XmlNode elResponse; XmlNode demResponse; Thread dThread = new Thread(delegate { //Web Service Call GetDemographics d = new GetDemographics(); demResponse = d.HIALRequest(DNode); }); Thread eThread = new Thread(delegate { //Web Service Call GetEligibility ge = new GetEligibility(); elResponse = ge.HIALRequest(ENode); }); dThread.Start(); eThread.Start(); dThread.Join(); eThread.Join(); //combine the resulting XML and return it. //Maybe throw a bit of logging in to make architecture happy Another option we thought of is to create a worker class, and pass it the service information and have it execute. This would allow us to have a bit more control over what is going on, but could add additional overhead. Another option brought up would be 2 asynchronous calls and manage the returns through a loop. When the calls are completed (success or error) the loop picks it up and ends. The portal service will be called about 50,000 times a day. I don't want to gold plate this sucker. I'm looking for something light weight. The services that are being called on the broker do have time out limits set, and are already heavily logged and audited, so I'm not worried on that part. This is .NET 2.0 , and as much as I would love to upgrade I can't right now. So please leave all the goodies of 2.0 out please.

    Read the article

  • In Perl, how can I wait for threads to end in parallel?

    - by Pmarcoen
    I have a Perl script that launches 2 threads,one for each processor. I need it to wait for a thread to end, if one thread ends a new one is spawned. It seems that the join method blocks the rest of the program, therefore the second thread can't end until everything the first thread does is done which sort of defeats its purpose. I tried the is_joinable method but that doesn't seem to do it either. Here is some of my code : use threads; use threads::shared; @file_list = @ARGV; #Our file list $nofiles = $#file_list + 1; #Real number of files $currfile = 1; #Current number of file to process my %MSG : shared; #shared hash $thr0 = threads->new(\&process, shift(@file_list)); $currfile++; $thr1 = threads->new(\&process, shift(@file_list)); $currfile++; while(1){ if ($thr0->is_joinable()) { $thr0->join; #check if there are files left to process if($currfile <= $nofiles){ $thr0 = threads->new(\&process, shift(@file_list)); $currfile++; } } if ($thr1->is_joinable()) { $thr1->join; #check if there are files left to process if($currfile <= $nofiles){ $thr1 = threads->new(\&process, shift(@file_list)); $currfile++; } } } sub process{ print "Opening $currfile of $nofiles\n"; #do some stuff if(some condition){ lock(%MSG); #write stuff to hash } print "Closing $currfile of $nofiles\n"; } The output of this is : Opening 1 of 4 Opening 2 of 4 Closing 1 of 4 Opening 3 of 4 Closing 3 of 4 Opening 4 of 4 Closing 2 of 4 Closing 4 of 4

    Read the article

  • Using the Queue class in Python 2.6

    - by voipme
    Let's assume I'm stuck using Python 2.6, and can't upgrade (even if that would help). I've written a program that uses the Queue class. My producer is a simple directory listing. My consumer threads pull a file from the queue, and do stuff with it. If the file has already been processed, I skip it. The processed list is generated before all of the threads are started, so it isn't empty. Here's some pseudo-code. import Queue, sys, threading processed = [] def consumer(): while True: file = dirlist.get(block=True) if file in processed: print "Ignoring %s" % file else: # do stuff here dirlist.task_done() dirlist = Queue.Queue() for f in os.listdir("/some/dir"): dirlist.put(f) max_threads = 8 for i in range(max_threads): thr = Thread(target=consumer) thr.start() dirlist.join() The strange behavior I'm getting is that if a thread encounters a file that's already been processed, the thread stalls out and waits until the entire program ends. I've done a little bit of testing, and the first 7 threads (assuming 8 is the max) stop, while the 8th thread keeps processing, one file at a time. But, by doing that, I'm losing the entire reason for threading the application. Am I doing something wrong, or is this the expected behavior of the Queue/threading classes in Python 2.6?

    Read the article

  • Multithreading A Function in VB.Net

    - by Ben
    I am trying to multi thread my application so as it is visible while it is executing the process, this is what I have so far: Private Sub SendPOST(ByVal URL As String) Try Dim DataBytes As Byte() = Encoding.ASCII.GetBytes("") Dim Request As HttpWebRequest = TryCast(WebRequest.Create(URL.Trim & "/webdav/"), HttpWebRequest) Request.Method = "POST" Request.ContentType = "application/x-www-form-urlencoded" Request.ContentLength = DataBytes.Length Request.Timeout = 1000 Request.ReadWriteTimeout = 1000 Dim PostData As Stream = Request.GetRequestStream() PostData.Write(DataBytes, 0, DataBytes.Length) Dim Response As WebResponse = Request.GetResponse() Dim ResponseStream As Stream = Response.GetResponseStream() Dim StreamReader As New IO.StreamReader(ResponseStream) Dim Text As String = StreamReader.ReadToEnd() PostData.Close() Catch ex As Exception If ex.ToString.Contains("401") Then TextBox2.Text = TextBox2.Text & URL & "/webdav/" & vbNewLine End If End Try End Sub Public Sub G0() Dim siteSplit() As String = TextBox1.Text.Split(vbNewLine) For i = 0 To siteSplit.Count - 1 Try If siteSplit(i).Contains("http://") Then SendPOST(siteSplit(i).Trim) Else SendPOST("http://" & siteSplit(i).Trim) End If Catch ex As Exception End Try Next End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim t As Thread t = New Thread(AddressOf Me.G0) t.Start() End Sub However, the 'G0' sub code is not being executed at all, and I need to multi thread the 'SendPOST' as that is what slows the application.

    Read the article

  • Is it possible to Kick off a java process under Windows Service with C#?

    - by Wing C. Chen
    I would like to wrap a java program into a windows service with C# using System.ServiceProcess.ServiceBase. So I came up with the following code: /// <summary> /// The main entry point for the application. /// </summary> static void Main() { System.ServiceProcess.ServiceBase.Run(new JavaLauncher()); } protected override void OnStart(string[] args) { Thread _thread; _thread = new Thread(StartService); _thread.Start(); base.OnStart(args); } protected override void OnStop() { Thread _thread; _thread = new Thread(StopService); _thread.Start(); base.OnStop(); } static public void StartService() { System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents = false; proc.StartInfo.FileName = "javaw"; proc.StartInfo.Arguments = config.generateLaunchCommand(); proc.Start(); } static public void StopService() { System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents = false; proc.StartInfo.FileName = "javaw"; proc.StartInfo.Arguments = "-jar stop.jar"; proc.Start(); } Firstly I had to use Threads in OnStart and OnStop. If not, an exception occurs complaining that the service is terminated because of doing nothing. Secondly, the service can be hooked up to windows smoothly. However, the service terminates a short while after it is started. I looked into the process monitor, only the service process stays alive for that short while, the javaw process never showed up, however. Is there anyone who knows how this can be fixed? It works fine in an ordinary console environment. I think it has something to do with Windows service.

    Read the article

  • MapView EXC_BAD_ACCESS (SIGSEGV) and KERN_INVALID_ADDRESS

    - by user768113
    I'm having some 'issues' with my application... well, it crashes in an UIViewController that is presented modally, there the user enters information through UITextFields and his location is tracked by a MapView. Lets call this view controller "MapViewController" When the user submits the form, I call a different ViewController - modally again - that processes this info and a third one answers accordingly, then go back to a MenuVC using unwinding segues, which then calls MapViewController and so on. This sequence is repeated many times, but it always crashes in MapViewController. Looking at the crash log, I think that the MapView can be the problem of this or some element in the UI (because of the UIKit framework). I tried to use NSZombie in order to track a memory issue but it doesn't give me a clue about whats happening. Here is the crash log Hardware Model: iPad3,4 Process: MyApp [2253] OS Version: iOS 6.1.3 (10B329) Report Version: 104 Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Codes: KERN_INVALID_ADDRESS at 0x00000044 Crashed Thread: 0 Thread 0 name: Dispatch queue: com.apple.main-thread Thread 0 Crashed: 0 IMGSGX554GLDriver 0x328b9be0 0x328ac000 + 56288 1 IMGSGX554GLDriver 0x328b9b8e 0x328ac000 + 56206deallocated instance 2 IMGSGX554GLDriver 0x328bc2f2 0x328ac000 + 66290 3 IMGSGX554GLDriver 0x328baf44 0x328ac000 + 61252 4 libGPUSupportMercury.dylib 0x370f86be 0x370f6000 + 9918 5 GLEngine 0x34ce8bd2 0x34c4f000 + 629714 6 GLEngine 0x34cea30e 0x34c4f000 + 635662 7 GLEngine 0x34c8498e 0x34c4f000 + 219534 8 GLEngine 0x34c81394 0x34c4f000 + 205716 9 VectorKit 0x3957f4de 0x394c7000 + 754910 10 VectorKit 0x3955552e 0x394c7000 + 582958 11 VectorKit 0x394d056e 0x394c7000 + 38254 12 VectorKit 0x394d0416 0x394c7000 + 37910 13 VectorKit 0x394cb7ca 0x394c7000 + 18378 14 VectorKit 0x394c9804 0x394c7000 + 10244 15 VectorKit 0x394c86a2 0x394c7000 + 5794 16 QuartzCore 0x354a07a4 0x35466000 + 239524 17 QuartzCore 0x354a06fc 0x35466000 + 239356 18 IOMobileFramebuffer 0x376f8fd4 0x376f4000 + 20436 19 IOKit 0x344935aa 0x34490000 + 13738 20 CoreFoundation 0x33875888 0x337e9000 + 575624 21 CoreFoundation 0x338803e4 0x337e9000 + 619492 22 CoreFoundation 0x33880386 0x337e9000 + 619398 23 CoreFoundation 0x3387f20a 0x337e9000 + 614922 24 CoreFoundation 0x337f2238 0x337e9000 + 37432 25 CoreFoundation 0x337f20c4 0x337e9000 + 37060 26 GraphicsServices 0x373ad336 0x373a8000 + 21302 27 UIKit 0x3570e2b4 0x356b7000 + 357044 28 MyApp 0x000ea12e 0xe9000 + 4398 29 MyApp 0x000ea0e4 0xe9000 + 4324 I think thats all, additionally, I would like to ask you: if you are using unwind segues then you are releasing view controllers from the memory heap, right? Meanwhile, performing segues let you instantiate those controllers. Technically, MenuVC should be the only VC alive in the heap during the app life cycle if you understand me.

    Read the article

  • C: Fifo between threads, writing and reading strings

    - by Yonatan
    Hello once more dear internet, I writing a small program that among other things, writes a log file of commands received. to do that, I want to use a thread that all it should do is just attempt to read from a pipe, while the main thread will write into that pipe whenever it should. Since i don't know the length of each string command, i thought about writing and reading the pointer to the char buf[MAX_MESSAGE_LEN]. Since what i've tried so far doesn't work, i'll post my best effort :P char str[] = "hello log thread 123456789 10 11 12 13 14 15 16 17 18 19\n"; if (pipe(pipe_fd) != 0) return -1; pthread_t log_thread; pthread_create(&log_thread,NULL, log_thread_start, argv[2]); success_write = 0; do { write(pipe_fd[1],(void*)&str,sizeof(char*)); } while (success_write < sizeof(char*)); and the thread does this: char buffer[MAX_MSGLEN]; int success_read; success_read = 0; //while(1) { do { success_read += read(pipe_fd[0],(void*)&buffer, sizeof(char*)); } while (success_read < sizeof(char*)); //} printf("%s",buffer); (Sorry if this doesn't indent, i can't seem to figure out this editor...) oh, and pipe_fd[2] is a global parameter. So, any help with this, either by the way i thought of, or another way i could read strings without knowing the length, would be much appreciated. On a side note, i'm working on Eclipse IDE C/C++, version 1.2.1 and i can't seem to set up the compiler so it will link the pthread library to my project. I've resorted to writing my own Makefile to make it (pun intended :P) work. Anyone knows what to do ? i've looked online, but all i find are solutions that are probably good on an older version because the tabs and option keys are different. Anyways, Thanks a bunch internet ! Yonatan

    Read the article

  • My python program always brings down my internet connection after several hours running, how do I debug and fix this problem?

    - by Shane
    I'm writing a python script checking/monitoring several server/websites status(response time and similar stuff), it's a GUI program and I use separate thread to check different server/website, and the basic structure of each thread is using an infinite while loop to request that site every random time period(15 to 30 seconds), once there's changes in website/server each thread will start a new thread to do a thorough check(requesting more pages and similar stuff). The problem is, my internet connection always got blocked/jammed/messed up after several hours running of this script, the situation is, from my script side I got urlopen error timed out each time it's requesting a page, and from my FireFox browser side I cannot open any site. But the weird thing is, the moment I close my script my Internet connection got back on immediately which means now I can surf any site through my browser, so it must be the script causing all the problem. I've checked the program carefully and even use del to delete any connection once it's used, still get the same problem. I only use urllib2, urllib, mechanize to do network requests. Anybody knows why such thing happens? How do I debug this problem? Is there a tool or something to check my network status once such situation occurs? It's really bugging me for a while... By the way I'm behind a VPN, does it have something to do with this problem? Although I don't think so because my network always get back on once the script closed, and the VPN connection never drops(as it appears) during the whole process.

    Read the article

  • Clarification on Threads and Run Loops In Cocoa

    - by dubbeat
    I'm trying to learn about threading and I'm thoroughly confused. I'm sure all the answers are there in the apple docs but I just found it really hard to breakdown and digest. Maybe somebody could clear a thing or 2 up for me. 1)performSelectorOnMainThread Does the above simply register an event in the main run loop or is it somehow a new thread even though the method says "mainThread"? If the purpose of threads is to relieve processing on the main thread how does this help? 2) RunLoops Is it true that if I want to create a completely seperate thread I use "detachNewThreadSelector"? Does calling start on this initiate a default run loop for the thread that has been created? If so where do run loops come into it? 3) And Finally , I've seen examples using NSOperationQueue. Is it true to say that If you use performSelectorOnMainThread the threads are in a queue anyway so NSOperation is not needed? 4) Should I forget about all of this and just use the Grand Central Dispatch instead?

    Read the article

  • Capturing stdout from an imported module in wxpython and sending it to a textctrl, without blocking the GUI

    - by splafe
    There are alot of very similar questions to this but I can't find one that applies specifically to what I'm trying to do. I have a simulation (written in SimPy) that I'm writing a GUI for, the main output of the simulation is text - to the console from 'print' statements. Now, I thought the simplest way would be to create a seperate module GUI.py, and import my simulation program into it: import osi_model I want all the print statements to be captured by the GUI and appear inside a Textctrl, which there's countless examples of on here, along these lines: class MyFrame(wx.Frame): def __init__(self, *args, **kwds): <general frame initialisation stuff..> redir=RedirectText(self.txtCtrl_1) sys.stdout=redir class RedirectText: def __init__(self,aWxTextCtrl): self.out=aWxTextCtrl def write(self,string): self.out.WriteText(string) I am also starting my simulation from a 'Go' button: def go_btn_click(self, event): print 'GO' self.RT = threading.Thread(target=osi_model.RunThis()) self.RT.start() This all works fine, and the output from the simulation module is captured by the TextCtrl, except the GUI locks up and becomes unresponsive - I still need it to be accessible (at the very minimum to have a 'Stop' button). I'm not sure if this is a botched attempt at creating a new thread that I've done here, but I assume a new thread will be needed at some stage in this process. People suggest using wx.CallAfter, but I'm not sure how to go about this considering the imported module doesn't know about wx, and also I can't realistically go through the entire simulation architecture and change all the print statements to wx.CallAfter, and any attempt to capture the shell from inside the imported simulation program leads to the program crashing. Does anybody have any ideas about how I can best achieve this? So all I really need is for all console text to be captured by a TextCtrl while the GUI remains responsive, and all text is solely coming from an imported module. (Also, secondary question regarding a Stop button - is it bad form to just kill the simulation thread?). Thanks, Duncan

    Read the article

  • In Silverlight 3 how can I get the call to HtmlPage.Plugin.SetStyleAttribute() call to call other co

    - by John Rennemeyer
    I'm trying to take a snapshot of my Silverlight control using WriteableBitmap and it works fine, however, it only takes a snapshot of what is showing. I'm trying to resize the Silverlight control so it will show everything and then take a screenshot, however, the code doesn't resize the control until after the code after the call all runs which is the snapshot code... I can get this work using a timer to fire the snapshot after the other code has caused the resize but I'm wondering if there is a better way. The HtmlPage.Plugin.SetStyleAttribute call has to be called from the UI thread so I'm assuming that's where the problem is. The fact that it is being dispatched onto the UI thread while the rest of the code is not and so the other code is being run first. Is there anyway to create a new event or attach to the call to determine when it has been run to then fire off my snapshot code? I have the following code: private void btnTakeSnapshot_Click(object sender, System.Windows.RoutedEventArgs e) { if (CurrentContractAction != null) { string heightBefore = HtmlPage.Plugin.GetStyleAttribute("height"); HtmlPage.Plugin.SetStyleAttribute("height", string.Format("{0}px", "1800")); //this line doesn't change the height until after the "TakeSnapshot" code is run for some reason, I'm thinking it is because it is most likely dispatched to the UI thread :( and the following code is not run on the UI thread Snapshot snapshot = new Snapshot(string.Format("Action_Schedule_{0}", CurrentContractAction.Title), LayoutRoot, LayoutRoot, busyIndicatorDataGrid); snapshot.HideElements(btnViewGanttChart, btnSave, btnEditAction, btnFullScreen, btnTakeSnapshot, btnLockAndSubmit); snapshot.TakeSnapshot(); snapshot.ResetElementsVisibility(); HtmlPage.Plugin.SetStyleAttribute("height", string.Format("{0}px", heightBefore)); } } Thanks, John

    Read the article

  • Android CursorAdapters, ListViews and background threads

    - by MattC
    This application I've been working on has databases with multiple megabytes of data to sift through. A lot of the activities are just ListViews descending through various levels of data within the databases until we reach "documents", which is just HTML to be pulled from the DB(s) and displayed on the phone. The issue I am having is that some of these activities need to have the ability to search through the databases by capturing keystrokes and re-running the query with a "like %blah%" in it. This works reasonably quickly except when the user is first loading the data and when the user first enters a keystroke. I am using a ResourceCursorAdapter and I am generating the cursor in a background thread, but in order to do a listAdapter.changeCursor(), I have to use a Handler to post it to the main UI thread. This particular call is then freezing the UI thread just long enough to bring up the dreaded ANR dialog. I'm curious how I can offload this to a background thread totally so the user interface remains responsive and we don't have ANR dialogs popping up. Just for full disclosure, I was originally returning an ArrayList of custom model objects and using an ArrayAdapter, but (understandably) the customer pointed out it was bad memory-manangement and I wasn't happy with the performance anyways. I'd really like to avoid a solution where I'm generating huge lists of objects and then doing a listAdapter.notifyDataSetChanged/Invalidated() Here is the code in question: private Runnable filterDrugListRunnable = new Runnable() { public void run() { if (filterLock.tryLock() == false) return; cur = ActivityUtils.getIndexItemCursor(DrugListActivity.this); if (cur == null || forceRefresh == true) { cur = docDb.getItemCursor(selectedIndex.getIndexId(), filter); ActivityUtils.setIndexItemCursor(DrugListActivity.this, cur); forceRefresh = false; } updateHandler.post(new Runnable() { public void run() { listAdapter.changeCursor(cur); } }); filterLock.unlock(); updateHandler.post(hideProgressRunnable); updateHandler.post(updateListRunnable); } };

    Read the article

  • php while loop throwing a error over a $var < 10 statement

    - by William
    Okay, so for some reason this is giving me a error as seen here: http://prime.programming-designs.com/test_forum/viewboard.php?board=0 However if I take away the '&& $cur_row < 10' it works fine. Why is the '&& $cur_row < 10' causing me a problem? $sql_result = mysql_query("SELECT post, name, trip, Thread FROM (SELECT MIN(ID) AS min_id, MAX(ID) AS max_id, MAX(Date) AS max_date FROM test_posts GROUP BY Thread ) t_min_max INNER JOIN test_posts ON test_posts.ID = t_min_max.min_id WHERE Board=".$board." ORDER BY max_date DESC", $db); $num_rows = mysql_num_rows($sql_result); $cur_row = 0; while($row = mysql_fetch_row($sql_result) && $cur_row < 10) { $sql_max_post_query = mysql_query("SELECT ID FROM test_posts WHERE Thread=".$row[3].""); $post_num = mysql_num_rows($sql_max_post_query); $post_num--; $cur_row++; echo''.$cur_row.'<br/>'; echo'<div class="postbox"><h4>'.$row[1].'['.$row[2].']</h4><hr />' .$row[0]. '<br /><hr />[<a href="http://prime.programming-designs.com/test_forum/viewthread.php?thread='.$row[3].'">Reply</a>] '.$post_num.' posts omitted.</div>'; }

    Read the article

  • Java's Swing Threading

    - by nevets1219
    My understanding is that if I start up another thread to perform some actions, I would need to SwingUtilities.invokeAndWait or SwingUtilities.invokeLater to update the GUI while I'm in said thread. Please correct me if I'm wrong. What I'm trying to accomplish is relatively straightforward: when the user clicks submit, I want to (before performing any actions) disable the submit button, perform the action, and at the end of the action re-enable the button. My method to perform the action updates the GUI directly (displays results) when it gets the results back. This action basically queries a server and gets some results back. What I have so far is: boolean isRunning = false; synchronized handleButtonClick() { if ( isRunning == false ) { button.setEnabled( false ); isRunning = true; doAction(); } } doAction() { new Thread() { try { doAction(); // Concern A } catch ( ... ) { displayStackTrace( ... ); // Concern B } finally { SwingUtilities.invokeLater ( /* simple Runnable to enable button */ ); isRunning = false; } } } For both of my concerns above, do I would have to use SwingUtilities.invokeAndWait since they both will update the GUI? All GUI updates revolve around updating JTextPane. Do I need to in my thread check if I'm on EDT and if so I can call my code (regardless of whether it updates the GUI or not) and NOT use SwingUtilities.invokeAndWait?

    Read the article

  • javascript error of unterminated string

    - by OM The Eternity
    I want pass a parameter of javascript functiona which is a string. This javascript function is a hintbox on mousehover.. and the string i am using is like this: Hemmed Finish: Every side/edge (1/2" to 2") of the banner are folded and glued (special vinyl solution) or heat pressed. This is the most common and best finish option. Stitched Finish: Every side/edge (1" to 2") of the banner are folded in the back and stitched/sewed with white thread. This is not a common option as thread can be seen on the banner. Now in the hintbox on mousehover the above given text has to be display as it is displayed above along with the paragraph break.. But when i pass the above as parameter in that function along with appending some backslashes to recognise some punctuation, iots till gives me javascript error of unterminated string... I am doing this: onMouseover="showhint('Hemmed Finish\: Every side/edge \(1/2\'\' to 2\'\'\) of the banner are folded and glued \(special vinyl solution\) or heat pressed. This is the most common and best finish option.Stitched Finish\: Every side/edge \(1\'\' to 2\'\'\) of the banner are folded in the back and stitched/sewed with white thread. This is not a common option as thread can be seen on the banner', this, event, '250px')" pls could u help me in rectifying the issue...

    Read the article

  • Are background threads a bad idea? Why?

    - by Matt Grande
    So I've been told what I'm doing here is wrong, but I'm not sure why. I have a webpage that imports a CSV file with document numbers to perform an expensive operation on. I've put the expensive operation into a background thread to prevent it from blocking the application. Here's what I have in a nutshell. protected void ButtonUpload_Click(object sender, EventArgs e) { if (FileUploadCSV.HasFile) { string fileText; using (var sr = new StreamReader(FileUploadCSV.FileContent)) { fileText = sr.ReadToEnd(); } var documentNumbers = fileText.Split(new[] {',', '\n', '\r'}, StringSplitOptions.RemoveEmptyEntries); ThreadStart threadStart = () => AnotherClass.ExpensiveOperation(documentNumbers); var thread = new Thread(threadStart) {IsBackground = true}; thread.Start(); } } (obviously with some error checking & messages for users thrown in) So my three-fold question is: a) Is this a bad idea? b) Why is this a bad idea? c) What would you do instead?

    Read the article

  • Do I need to using locking against integers in c++ threads

    - by Shane MacLaughlin
    The title says it all really. If I am accessing a single integer type (e.g. long, int, bool, etc...) in multiple threads, do I need to use a synchronisation mechanism such as a mutex to lock them. My understanding is that as atomic types, I don't need to lock access to a single thread, but I see a lot of code out there that does use locking. Profiling such code shows that there is a significant performance hit for using locks, so I'd rather not. So if the item I'm accessing corresponds to a bus width integer (e.g. 4 bytes on a 32 bit processor) do I need to lock access to it when it is being used across multiple threads? Put another way, if thread A is writing to integer variable X at the same time as thread B is reading from the same variable, is it possible that thread B could end up a few bytes of the previous value mixed in with a few bytes of the value being written? Is this architecture dependent, e.g. ok for 4 byte integers on 32 bit systems but unsafe on 8 byte integers on 64 bit systems? Edit: Just saw this related post which helps a fair bit.

    Read the article

  • selenium and firefox timeout behavior

    - by Md. Reazul Karim
    I am facing this strange timeout behavior. I tried to load some page using: WebDriver drv = new FirefoxDriver(); drv.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); drv.get(url); String email = ""; try { WebElement aElem = Util.safeFindElementByXpath(drv, "//p[1]/a[1]"); if (aElem != null) { email = aElem.getAttribute("href"); } } catch (Exception e) { } drv.quit(); return email; The safeFindElementByXpath is: static WebElement safeFindElementByXpath(WebDriver driver, String xpath) { try { return driver.findElement(By.xpath(xpath)); } catch (NoSuchElementException e) { return null; } } Now I set the firefox network.http.connection-timeout and network.http.connection-retry-timeout both to 10. Now if I restart the firefox I can see the new values. But if I try to run the above code - the firefox window opens and it waits for a particular website for a long time. Hence I open another tab in the same firefox window and check the values of timeout and find them to be 90 and 250. If I change the values on that same window, the selenium code immediately finishes requesting for the page (ie it goes after the exception block). So the thing is that the same code will work on many sites and I don't know beforehand which site is invalid/down and I was thinking of putting this code in a separate thread and kill the thread after some time from the calling thread. But that is not possible I guess because the child thread has no way to poll anything as it is stuck at page request and can't go to the polling code afterwards. Now the thing is that I want any kind of hack/workaround to accomplish this: try getting the emails for good sites and if there are bad sites just give up after a certain period (press the panic button sorta thing). Thanks

    Read the article

  • threading in Python taking up too much CPU

    - by KevinShaffer
    I wrote a chat program and have a GUI running using Tkinter, and to go and check when new messages have arrived, I create a new thread so Tkinter keeps doing its thing without locking up while the new thread goes and grabs what I need and updates the Tkinter window. This however becomes a huge CPU hog, and my guess is that it has to do somehow with the fact that the Thread is started and never really released when the function is done. Here's the relevant code (it's ugly and not optimized at the moment, but it gets the job done, and itself does not use too much processing power, as when I run it not threaded, it doesn't take up much CPU but it locks up Tkinter) Note: This is inside of a class, hence the extra tab. def interim(self): threading.Thread(target=self.readLog).start() self.after(5000,self.interim) def readLog(self): print 'reading' try: length = len(str(self.readNumber)) f = open('chatlog'+str(myport),'r') temp = f.readline().replace('\n','') while (temp[:length] != str(self.readNumber)) or temp[0] == '<': temp = f.readline().replace('\n','') while temp: if temp[0] != '<': self.updateChat(temp[length:]) self.readNumber +=1 else: self.updateChat(temp) temp = f.readline().replace('\n','') f.close() Is there a way to better manage the threading so I don't consume 100% of the CPU very quickly?

    Read the article

  • Revalidate and repaint - Java Swing

    - by bosra
    I have a JPanel that I am adding JLabel's to. I then want to remove all the JLabels and add some new ones. So I do the following: panel.removeAll();panel.repaint(); panel.add(new JLabel("Add something new"); panel.revalidate(); This works fine. My problem arises when I start a new thread after this like: panel.removeAll();panel.repaint(); (1)panel.add(new JLabel("Add something new"); panel.revalidate(); //new thread to start - this thread creates new JLabels that should appear under (1) firstProducer.start(); try { firstProducer.join(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } Then the output from the original JLabels is still visible. I have read that the revalidate process is a long running task and hence the firstProducer thread is getting started while the revalidation is going on and a conflict is arising. What is the best way to deal with this?

    Read the article

< Previous Page | 89 90 91 92 93 94 95 96 97 98 99 100  | Next Page >