Running in separate thread??

Hi
I have a code which generates a pdf file. What i wan is for it to run in a separate thread. The filling and creation of the pdf file should be running while i am doing other stuffs.. just like in downloading. the user can browse or do other things in the mean time while waiting.. when the pdf file is ready to be viewed, then the program should interupt whatever the user is doing and pop up a pdf viewer to display the file.
Is there any way to call the pdf viewer in my code? And how should i do the interrupt? Plus, how do i specify that the pdf creation should run in a separate thread?
thanks in advance.
tbozu

alright, handling the interrupt is highly dependant on the rest of your application, so I won't touch that one, but.
To create your file in a different thread, wrap the method in it's own thread, so it would look similar to
new Thread() {
public void run() {
writeMyFile(); // your method here
}.start();then, to start the pdf viewer, try using the Runtime.exec() utilities.
good luck to you!

Similar Messages

  • Having 2 objects running in separate threads

    I am accessing cobol programs using the microfocus runtime for java. The problem with it is that a you can only run one instance of a cobol program at the same time, unless they are in separate threads.
    Example:
    CobolTextSearch cobol1 = new CobolTextSearch();
    CobolTextSearch cobol2 = new CobolTextSearch();
    cobol1.execute("FAMILY");
    cobol2.execute("HISTORY");
    System.out.println(cobol1.getRecord());
    System.out.println(cobol2.getRecord());The output of this program results in HISTORY for cobol1 and HISTORY for cobol2. Where as if they were run in separate threads, I would have got FAMILY for cobol1.
    So my question is, is there any way I can run these two objects in separate threads so that any time I access the object it will be in its own thread? I cant just run them in separate threads on the execute because each getRecord is interfacing with cobol. After execute I want to be able to read values from the cobol files to see if they match without having to read each record into memory on the java side.

    No you are not missing anything, you just create a new thread each time you run something or you have to make a setter method to accept parameters for the next run and then a seperate method to actually make your routine execute.
    public void setTask(String s){
      task2Execute = s; //task2Execute is global to the methods
    public boolean runTask(){
      CobolTextSearch cobol = new CobolTextSearch();
      cobol1.execute(task2Execute);
    //  other logic
    }Here is what the docs say about threads: A thread is a thread of execution in a program. The Java Virtual Machine allows an application to have multiple threads of execution running concurrently.

  • Export from Crystal Reports 2008 viewer fails if run on separate thread

    I have a windows desktop application written in Visual Basic using Visual Studio 2008.  I have installed and am trying Crystal Reports 2008 to run a report.  Everything seems to work well except that when I preview a report (using the viewer control) and click the export button found in the upper left corner of that control, I get the following message:
    Error 5: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made.  Ensure that your Main function has STAThreadAttribute marked on it.  This exception is only raised if a debugger is attached to the process.
    I am a little confused on what to do exactly.  Is the problem because I am running in the Visual Studio 2008 IDE?  It says this exception is only raise if a debugger is attached to the process.  No, I tried running it outside the IDE.  The exception wasn't generated but the application hung when the button was clicked.
    It says the current thread must be set to single thread apartment (STA) mode.  If the report is run on its own thread, is the "current" thread the thread the report is running on or is the main application's UI thread?  I don't think I want to set my main application to single thread apartment mode because it is a multi-threaded application (although I really don't know for sure because I am new to multi-threaded programming). 
    My objective is to allow reports to run asynchronously so that the user can do other things while it is being generated.  Here is the code I use to do this:
        ' Previews the report using a new thread (asynchronously)
        Public Sub PreviewReportAsynch(ByVal sourceDatabase As clsMainApplicationDatabase)
            Dim backgroundProcess As System.ComponentModel.BackgroundWorker
            ' Start a new thread to run this report.
            backgroundProcess = New System.ComponentModel.BackgroundWorker
            Using (backgroundProcess)
                ' Wire the function we want to run to the 'do work' event.
                AddHandler backgroundProcess.DoWork, AddressOf PreviewReportAsynch_Start
                ' Kick off the report asynchronously and return control to the calling process
                backgroundProcess.RunWorkerAsync(sourceDatabase)
            End Using
        End Sub
        Private Sub PreviewReportAsynch_Start(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs)
            ' The source database needed to call preview report was passed as the only argument
            Call PreviewReport(CType(e.Argument, clsMainApplicationDatabase))
        End Sub
        ' Previews the report.  From the preview window, the user can print it.
        Public Function PreviewReport(ByVal sourceDatabase As clsMainApplicationDatabase) As FunctionEndedResult
            Dim errorBoxTitle As String
            Dim frmPreview As frmReportPreview
            ' Setup error handling
            errorBoxTitle = "Preview " & Name & " Report"
            PreviewReport = FunctionEndedResult.FAILURE
            On Error GoTo PreviewError
            ' Set up the crxReport object
            If InitializeReportProcess(sourceDatabase) <> FunctionEndedResult.SUCCESS Then
                GoTo PreviewExit
            End If
            ' Use the preview form to preview the report
            frmPreview = New frmReportPreview
            frmPreview.Report = crxReport
            frmPreview.ShowDialog()
            ' Save any settings that should persist from one run to the next
            Call SavePersistentSettings()
            ' If we got this far everything is OK.
            PreviewReport = FunctionEndedResult.SUCCESS
    PreviewExit:
            ' Do any cleanup work
            Call CleanupReportProcess(sourceDatabase)
            Exit Function
    PreviewError:
            ' Report error then exit gracefully
            ErrorBox(errorBoxTitle)
            Resume PreviewExit
        End Function
    The variable crxReport is of type ReportDocument and the windows form called 'frmPreview' has only 1 control, the crystal reports viewer. 
    The print button on the viewer works fine.  Just the export button is failing.  Any ideas?

    Hi Trevor.
    Thank you for the reply.  The report document is create on the main UI thread of my application.  The preview form is created and destroyed on the separate thread.  For reasons I won't get into, restructuring the code to move all the initialization stuff inside the preview form is not an option (OK, if you a really curious, I don't always preview a report, sometimes I print and/or export it directly which means the preview form isn't used).
    What I learned through some other research is that there are some things (like COM calls and evidently some OLE automation stuff) that cannot be run on a thread that uses the MTA threading model.   The export button probably uses some of this technology, thus the message stating that an STA threading model is required.  I restructured the code as follows to accomodate this requirement.  Here is a sample:
    ' Previews the report using a new thread (asynchronously)
        Public Sub PreviewReportAsynch(ByVal sourceDatabase As clsMainApplicationDatabase)
            Dim staThread As System.Threading.Thread
            ' Start the preview report function on a new thread
            staThread = New System.Threading.Thread(AddressOf PreviewReportAsynchStep1)
            staThread.SetApartmentState(System.Threading.ApartmentState.MTA)
            staThread.Start(sourceDatabase)
        End Sub
        Private Sub PreviewReportAsynchStep1(ByVal sourceDatabase As Object)
            Dim staThread As System.Threading.Thread
            ' Initialize report preview.  This includes staging any data and configuring the
            ' crystal report document object for use by the crystal report viewer control.
            If InitializeReportProcess(DirectCast(sourceDatabase, clsMainApplicationDatabase)) = FunctionEndedResult.SUCCESS Then
                ' Show the report to the user.  This must be done on an STA thread so we will
                ' start another of that type.  See description of PreviewReportAsynchStep2()
                staThread = New System.Threading.Thread(AddressOf PreviewReportAsynchStep2)
                staThread.SetApartmentState(System.Threading.ApartmentState.STA)
                staThread.Start(mcrxReport)
                ' Wait for step 2 to finish.  This blocks the current thread, but this thread
                ' isn't the main UI thread and this thread has no UI anymore (the progress
                ' form was closed) so it won't matter that is it blocked.
                staThread.Join()
                ' Save any settings that should persist from one successful run to the next
                Call SavePersistentSettings()
            End If
            ' Release the crystal report
            Call CleanupReportProcess(DirectCast(sourceDatabase, clsMainApplicationDatabase))
        End Sub
        ' The preview form must be launched on a thread that use the single-threaded apartment (STA) model.
        ' Threads use the multi-threaded apartment (MTA) model by default.  This is necessary to make the
        ' export and print buttons on the preview form work.  They do not work when running on a
        ' thread using MTA.
        Public Sub PreviewReportAsynchStep2(ByVal crxInitializedReport As Object)
            Dim frmPreview As frmReportPreview
            ' Use the preview form to preview the report.  The preview form contains the crystal reports viewer control.
            frmPreview = New frmReportPreview
            frmPreview.Report = DirectCast(crxInitializedReport, ReportDocument)
            frmPreview.ShowDialog()
        End Sub
    Thanks for your help!
    Andy

  • How to stop Native Meto running in separate thread?

    I have a long working NM and run it in separate thread using SwingWorker class. If I want to stop that metod, i use interrupt(), but it seems to be a wrong way. It looks like NM go on working, and when I call other NM it throws an Access Violation Exception.
    Is there any ideas?
    Thank you. Charis.

    The interrupt() method does not stop the thread. It sets a flag. Are you checking that flag in your native code?

  • Timer in separate Thread.

    Hi.
    In my application i have a timer use to tick after every second and update a lable on UI. problem i was facing was that when time is enable none of the touch event was working.
    I googled it and found that i have to call timer function from another thread..
    after some effort i manage to run a separate thread. but now i m facing problems in calling a timer function here is the code.
    Create Thread
    myThread = [[NSThread alloc] initWithTarget:self selector:@selector(SapThread:) object:nil];
    [myThread start];
    SapThread Function....
    - (void)SapThread:(id)info {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    NSTimer *appTimer = [NSTimer scheduledTimerWithTimeInterval:(1/20) target:self selector:@selector(UpdateTime) userInfo:nil repeats:YES];
    [pool release];
    UpdateTime Function for timer
    -(void) UpdateTime
    //set lable value.
    problem is this that UpdateTime function never called.
    Thankz in advance
    Muhammad Usman Aleem

    As I tried to explain above, I didn't expect your code to work after you corrected the firing method signature.
    Your detached thread doesn't run until you release your myThread object. It terminates when execution reaches the end of your SapThread method. That's why the timer never fires when you run it in that thread.
    In any case, I think sptrakesh is absolutely correct. There's no reason a timer in the main thread should prevent you from catching touch events. So I think you have two major points of confusion:
    1) Your thread isn't doing anything, since it terminates before the timer ever fires once;
    2) You have mis-diagnosed the problem with the touch events and don't need a new thread. I.e. even if you got a detached thread working to fire your timer, that's not going to solve your touch problem.
    I think bringing a new thread into the mix has gotten you in over your head and taken your attention away from the primary problem. So take sptrakesh's advice. Put the timer back into the main thread and focus on why you're not catching the events you want.

  • How can I debug a sequence that has a subsequence is running in a separate thread?

    Hi,
    How can I debug a sequence that has a subsequence is running in a separate thread?
    I have to have a continues check for a  digital in signal to be able to terminate the sequence if a physical button is pushed.
    This is running in a separate thread, but this way I cannot debug the main sequence.
    Is there any workaround for this?
    Thanks,
    Andras

    This KB might help you:
    http://digital.ni.com/public.nsf/websearch/46D1E157756C37E686256CED0075E156?OpenDocument
    Let me know if this does not help.
    Allen P.
    NI

  • Running SSRS report locally in separate thread

    We're using ASP.net with .Net 4, developing with Visual Studio 2012.  We use SSRS 2012sp1 with local reports, so exporting the report ourselves instead of using a reportviewer control (and not using the SQL Reporting service).  The reports are executing
    fine when we export the report in the main thread, but if we spawn a worker thread and run a report there we receive the following error when calling Render():
    Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: Failed to load expression host assembly. Details: Invalid token
    for impersonation - it cannot be duplicated.
    We only receive this when running a report that uses expressions on a separate thread.  I've tried running the application pool under all the default built-in accounts (NetworkService, etc), and under admin user accounts to no avail.
    This didn't occur with the previous version of our application which used .net 3.5.  From what I've read, its because of a new security model in .net 4.
    I've tried running the application pool under LocalSystem, that does not help.
    We are not loading any custom DLLs in the report.  I think its trying to load the expression DLL that SSRS compiles from expressions on the report.  We don't have any outside DLLs on the report, only basic report expressions.  This works fine
    in-process, it only fails when we try to run it on a separate thread.
    Microsoft.Reporting.WebForms.LocalProcessingException: An error occurred during local report processing. ---> Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: Failed to load expression host assembly. Details: Invalid token for impersonation - it cannot be duplicated.
    at Microsoft.ReportingServices.RdlExpressions.ReportRuntime.ProcessLoadingExprHostException(ObjectType assemblyHolderObjectType, Exception e, ProcessingErrorCode errorCode)
    at Microsoft.ReportingServices.RdlExpressions.ReportRuntime.LoadCompiledCode(IExpressionHostAssemblyHolder expressionHostAssemblyHolder, Boolean includeParameters, Boolean parametersOnly, ObjectModelImpl reportObjectModel, ReportRuntimeSetup runtimeSetup)
    at Microsoft.ReportingServices.OnDemandProcessing.Merge.Init(Boolean includeParameters, Boolean parametersOnly)
    at Microsoft.ReportingServices.OnDemandProcessing.Merge.Init(ParameterInfoCollection parameters)
    at Microsoft.ReportingServices.ReportProcessing.Execution.ProcessReportOdp.CreateReportInstance(OnDemandProcessingContext odpContext, OnDemandMetadata odpMetadata, ReportSnapshot reportSnapshot, Merge& odpMerge)
    at Microsoft.ReportingServices.ReportProcessing.Execution.ProcessReportOdp.Execute(OnDemandProcessingContext& odpContext)
    at Microsoft.ReportingServices.ReportProcessing.Execution.RenderReportOdpInitial.ProcessReport(ProcessingErrorContext errorContext, ExecutionLogContext executionLogContext, UserProfileState& userProfileState)
    at Microsoft.ReportingServices.ReportProcessing.Execution.RenderReport.Execute(IRenderingExtension newRenderer)
    at Microsoft.ReportingServices.ReportProcessing.ReportProcessing.RenderReport(IRenderingExtension newRenderer, DateTime executionTimeStamp, ProcessingContext pc, RenderingContext rc, IChunkFactory yukonCompiledDefinition)
    at Microsoft.Reporting.LocalService.CreateSnapshotAndRender(ReportProcessing repProc, IRenderingExtension renderer, ProcessingContext pc, RenderingContext rc, SubreportCallbackHandler subreportHandler, ParameterInfoCollection parameters, DatasourceCredentialsCollection credentials)
    at Microsoft.Reporting.LocalService.Render(String format, String deviceInfo, String paginationMode, Boolean allowInternalRenderers, IEnumerable dataSources, CreateAndRegisterStream createStreamCallback)
    at Microsoft.Reporting.WebForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, CreateAndRegisterStream createStreamCallback, Warning[]& warnings)
    --- End of inner exception stack trace ---
    at Microsoft.Reporting.WebForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, CreateAndRegisterStream createStreamCallback, Warning[]& warnings)
    at Microsoft.Reporting.WebForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings)
    at Microsoft.Reporting.WebForms.LocalReport.Render(String format, String deviceInfo, PageCountMode pageCountMode, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings)
    at Microsoft.Reporting.WebForms.Report.Render(String format, String deviceInfo, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings)
    at IxSS.Infolinx.Report.MicrosoftInfolinxReport.ExportReport(String strFileFullyQualifiedPath, String strExportType, String strFilterDesc, Dictionary`2 extraParams, String area)
    at IxSS.Infolinx.Report.MicrosoftInfolinxReport.ExportReport(String strFileFullyQualifiedPath, String strExportType, String strFilterDesc, Dictionary`2 extraParams)

    Was that a joke?
    If not, no, there is no duplicated token to run the report.  I'm guessing it means some sort of security token, but if its something to do with the user running the application pool, changing that user has no effect.  I've enabled and disabled
    asp.net impersonation to no effect as well.

  • Trouble with TestStand running VB DLLs compiles in separate threads

    I have an application that uses DLLs written in VB 6 to manipulate hardware. The hardware is Stepper Motors controlled via the NI CAN bus card, and two instruments controlled via the GPIB PCI card. I have written the two DLLs to use the same NI PCI GPIB and the same NI CAN BUS card. (One instrument per DLL and One Motor per DLL)
    Test stand is then creating the DLLs and running them in separate threads. I have the one DLL Call in a subsequence running as a separate thread, and the other DLL is in the main sequence. I have a GOTO step with preconditions set so that the main sequence only continues after the separate thread in the subsequence is finished.
    The problem I am having is that these D
    LLs work OK when I run them both in the VB debugger. The program even works when I run the main thread in the debugger, and the subsequence is run compiled.
    The problem is, that if I try to run both of these DLLs compiled It seems as if the subsequence DLL never executes.

    To Tuxamation -
    Nothing comes to mind as to why this would happen. VB 6 automation DLLs are used all the time for code modules.
    Note that when MSVB debugs a DLL, it is actually running the DLL as an EXE server within the MSVB process and not in TestStand's process that is using it. I typically found that there is typically a subtle difference in behavior between running the server as an EXE or DLL server.
    A simple way to determine if the TestStand call is reaching your DLL is to place a MsgBox function call in the DLL entry point and immediately return, ie. bybassing your existing code.
    So, if the call is being made to your DLL, you could then enable the Visual Basic project option on the Compile tab, "Create Symbol Debug Info" and recreate your VB DLL.
    You can then attach Microsoft Visual Studio (C++ debugger) to the TestStand process, open the file that contains the entry point in to DLL that TestStand calls, set a breakpoint, and see if the breakpoint is reached.
    Scott Richardson
    Scott Richardson
    National Instruments

  • Window doesn't close wheh Call Library Function Node set to Run in Any Thread

    This is a problem regarding Call Library Function Nodes running in the UI thread or any thread.
    I have a camera which has its own API supplied as a dll. I have created a set of VI wrappers which each call a function in the dll through a Call Library Function Node.
    Initially each CLFN was set to 'Run in the UI thread' (the default).
    To start the camera streaming images I call (through a CLFN)
    ICubeSDK_Start(int CamIndex, Hwnd, ImgHandle, bool Preview, bool callback);
    If Preview = True then the image is displayed in a preview window.
    If ImgHandle = NULL a default preview window
    is used.
    In the CLFN definition I define:
    ImgHandle as a U32
    Preview as a I32
    To stop the camera streaming images I call
        ICubeSDK_Stop(int CamIndex)
    In the actual implementation I set ImgHandle = 0 (NULL) and Preview = 1 (true).
    This all works fine, and a preview window is opened and images displayed. When I call ICubeSDK_Stop the preview window is closed.
    However, I would prefer to set the CLFN to 'Run in any thread' because
    a) when run in the UI thread the preview window randomly gets sent to the back when I switch focus between open VI windows (presumably because it is in the same thread as the VIs)
    b) I don't want to put unnecessary stuff in the UI thread
    c) my (naive?) understanding is that it is safer to run in any thread
    So I have set all CLFNs to 'Run in any thread'
    When I do this the preview window opens OK, and behaves like any other non LabVIEW controlled window in terms of focus. But when I call ICubeSDK_Stop() the preview window does not get closed properly, it just shows a blank image. I can't close it manually, there is no X in the corner and no option to close it from the taskbar. To get rid of it I have to close the LabVIEW project it is spawned from, which often results in a crash. It does appear as a separate item in task manager but if I 'end process' it, LabVIEW closes (and often crashes) as well.
    If I change only the CLFNs that call the Start and Stop functions back to 'Run in the UI thread' then it all works fine again, except that the preview window gets sent to the back randomly as before.
    So, what do I have to do to get the preview window to close properly if I set the CLFN to 'Run in any thread'.
    Alternatively, is there a way to close the window programmatically (ie force it to close) after I have called ICube_Stop.
    Thanks
    DAve

    Hi Dave,
    The "Run In UI Thread"  switches from the thread the VIs currently executing in to the user interface thread. If you select "Run in Any Thread", the Call Library Function Node continues in the currently executing thread. By default, all Call Library Function Nodes run in the User Interface thread.
    Before you configure the Call Library Function Node to run in any thread, you have to make sure that the code is thread safe. Code is thread safe when it does not store any global data (e.g. global variables, files on disks, etc.), does not access any hardware, does not make calls to any functions, libraries or drivers that are not thread safe.
    Unfortunately, since you said that your DLL accesses hardware, it is not recommended to use "Run in Any Thread." This is probably why you are seeing the crash.
    If your preview window gets sent to the back you can programmatically bring it forward. Here is an example of how this can be done: http://decibel.ni.com/content/docs/DOC-4551
    If you want to completely close the window down you can do so as described in this link: http://digital.ni.com/public.nsf/allkb/81E9C144190​0FFCE8625748F0055DBB0?OpenDocument
    I also thought you might find this useful: http://zone.ni.com/devzone/cda/tut/p/id/3009
    I hope this helps.
    Regards,
    Mahdieh G
    Applications Engineer
    National Instruments UK&Ireland

  • Using SSRS local mode, receive invalid token error when trying to export the report when running in worker thread

    We're using ASP.net with .Net 4, developing with Visual Studio 2012.  We use SSRS 2012sp1 with local reports, so exporting the report ourselves instead of using a reportviewer control (and not using the SQL Reporting service).  The reports are
    executing fine when we export the report in the main thread, but if we spawn a worker thread and run a report there we receive the following error when calling Render():
    Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: Failed to load expression host assembly. Details: Invalid token for impersonation - it cannot be duplicated.
    We only receive this when running a report that uses expressions on a separate thread.  I've tried running the application pool under all the default built-in accounts (NetworkService, etc), and under admin user accounts to no avail.
    This didn't occur with the previous version of our application which used .net 3.5.

    As mentioned, we are not using the Reportviewer control, we are rendering locally.  Not certain if that would make a difference.
    Also, I had tried using all the built-in accounts.  Just for kicks I changed it to LocalSystem again, then reset IIS (see image below).  I then tried to export the report in a worker thread and received the same error.
    Here is the text from the exception:
    Microsoft.Reporting.WebForms.LocalProcessingException: An error occurred during local report processing. ---> Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: Failed to load expression host assembly. Details: Invalid token for impersonation - it cannot be duplicated.
    at Microsoft.ReportingServices.RdlExpressions.ReportRuntime.ProcessLoadingExprHostException(ObjectType assemblyHolderObjectType, Exception e, ProcessingErrorCode errorCode)
    at Microsoft.ReportingServices.RdlExpressions.ReportRuntime.LoadCompiledCode(IExpressionHostAssemblyHolder expressionHostAssemblyHolder, Boolean includeParameters, Boolean parametersOnly, ObjectModelImpl reportObjectModel, ReportRuntimeSetup runtimeSetup)
    at Microsoft.ReportingServices.OnDemandProcessing.Merge.Init(Boolean includeParameters, Boolean parametersOnly)
    at Microsoft.ReportingServices.OnDemandProcessing.Merge.Init(ParameterInfoCollection parameters)
    at Microsoft.ReportingServices.ReportProcessing.Execution.ProcessReportOdp.CreateReportInstance(OnDemandProcessingContext odpContext, OnDemandMetadata odpMetadata, ReportSnapshot reportSnapshot, Merge& odpMerge)
    at Microsoft.ReportingServices.ReportProcessing.Execution.ProcessReportOdp.Execute(OnDemandProcessingContext& odpContext)
    at Microsoft.ReportingServices.ReportProcessing.Execution.RenderReportOdpInitial.ProcessReport(ProcessingErrorContext errorContext, ExecutionLogContext executionLogContext, UserProfileState& userProfileState)
    at Microsoft.ReportingServices.ReportProcessing.Execution.RenderReport.Execute(IRenderingExtension newRenderer)
    at Microsoft.ReportingServices.ReportProcessing.ReportProcessing.RenderReport(IRenderingExtension newRenderer, DateTime executionTimeStamp, ProcessingContext pc, RenderingContext rc, IChunkFactory yukonCompiledDefinition)
    at Microsoft.Reporting.LocalService.CreateSnapshotAndRender(ReportProcessing repProc, IRenderingExtension renderer, ProcessingContext pc, RenderingContext rc, SubreportCallbackHandler subreportHandler, ParameterInfoCollection parameters, DatasourceCredentialsCollection credentials)
    at Microsoft.Reporting.LocalService.Render(String format, String deviceInfo, String paginationMode, Boolean allowInternalRenderers, IEnumerable dataSources, CreateAndRegisterStream createStreamCallback)
    at Microsoft.Reporting.WebForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, CreateAndRegisterStream createStreamCallback, Warning[]& warnings)
    --- End of inner exception stack trace ---
    at Microsoft.Reporting.WebForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, CreateAndRegisterStream createStreamCallback, Warning[]& warnings)
    at Microsoft.Reporting.WebForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings)
    at Microsoft.Reporting.WebForms.LocalReport.Render(String format, String deviceInfo, PageCountMode pageCountMode, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings)
    at Microsoft.Reporting.WebForms.Report.Render(String format, String deviceInfo, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings)
    at IxSS.Infolinx.Report.MicrosoftInfolinxReport.ExportReport(String strFileFullyQualifiedPath, String strExportType, String strFilterDesc, Dictionary`2 extraParams, String area)
    at IxSS.Infolinx.Report.MicrosoftInfolinxReport.ExportReport(String strFileFullyQualifiedPath, String strExportType, String strFilterDesc, Dictionary`2 extraParams)

  • Cannot Open Form Created on Separate Thread After Closing

    My application communicates with a device that has several sensors.  As the sensors collect data, they send messages over the com port.  I have written a class to communicate with the device.  As the messages come in and are processed, the
    class raises events that the application responds to.
    The main window of the application handles the communication with the device and displays several statistics based on the data collected.  When the user presses a button on the device, a specific event is raised.  The main window create a separate
    thread and opens a child window.  When the child window is open, the user opens a valve to dispense the product.  As the product is dispensed, a flow meter connected to the device measures the volume of product dispensed.  The flow meter generates
    messages to indicate the volume dispensed.  I need to be able to send messages from the main window to the child window so that the child window displays the volume.  When the user is done, they close the valve dispensing the product and press the
    "End" button on the child window.  The child window then updates several variables on the main window, makes a couple of database calls to record how much product was dispensed and by whom and then closes.
    I need to run the child window using a separate thread as both windows need to be able to process commands.  If only one window has control the program doesn't work at all.  I have it figured out so that everything is working.  I can open
    the child window, dispense product, se the amount of product dispensed in the child window (the main window processes commands from the device and updates the label on the child window using a delegate), closes the window (using Me.Close()) and updates the
    main display with the updated data.  The problem is that when a user goes to dispense product a second time, I get the following error:
      A first chance exception of type 'System.ObjectDisposedException' occurred in System.Windows.Forms.dll
      Additional information: Cannot access a disposed object.
    I thought that maybe I could hide the window (change Me.Close() to Me.Hide) and then just show it.  When I do that I get this error:
      A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
      Additional information: Cross-thread operation not valid: Control 'frmPour' accessed from a thread other than the thread it was created on.
    Both of these errors make sense to me, I just can't figure out how to make it work.
    First I have to declare the child window as a global variable as I need to access the window from a couple of the event handlers in the main form.
    Public frmMeasure As New frmPour
    When the user presses the button on the device to dispense the product, the event handler executes this code to open the child window.
    Private Sub StartPour(sAuthName As String, sAuthToken As String, iStatus As Integer) Handles Device.Pour
    Dim th As System.Threading.Thread = New Threading.Thread(AddressOf Me.OpenDispenseWindow)
    th.SetApartmentState(ApartmentState.STA)
    th.Start()
    End If
    End Sub
    Which executes this code:
    Public Sub OpenDispenseWindow()
    frmMeasure.sNameProperty = sCurrentUserName
    frmMeasure.sAuthTokenIDProperty = sUserToken
    Application.Run(frmMeasure)
    bAuthenticated = False
    bPouring = False
    dSessionVolume += GetTapConversion(sCurrentValve) * iFinalTick
    UpdateDisplayDelegate(iValveID)
    End Sub
    It doesn't matter if I use Me.Close() or Me.Hide(), both methods fail on the Application.Run(frmMeasure) line with the errors shown above. 
    For the Me.Close() method, my thinking is that the global frmMeasure object is getting disposed when I close the child window.  Is there any way that I can re-instantiate it when I go to display the window again?
    For the Me.Hide method, is there any way that I can track the thread that created it in the main window and when I go to call it a second time, detect that it is already available and just Show() it?
    Any hints, tips or suggestions are appreciated.
    Thanks.
    John
    John

    To be honest, I have only grasped < 100% of your message in detail, but...: Windows that have a parent<->child relation must be running in the same thread. In addition, after closing a modeless window, you must not use it anymore. Instead, create
    a new instance.
    What happens if you do not create a new thread but instead open the child in the same thread (which is obligatory)? You wrote it doesn't work, but I don't know why?
    "First I have to declare the child window as a global variable".
    How do you define "global"? Normally this is a variable in a Module declared with the scope Public or Friend. But I guess you mean a field of the Form (a variable at class level in the Form).
    "I need to be able to send messages from the main window to the child window so that the child window displays the volume."
    Why does the main window has to send the messages? Can't the child window handle the device's messages itself?
    "I need to run the child window using a separate thread as both windows need to be able to process commands."
    Process commands from the device, or commands from the user operating the Forms?
    Armin

  • Is the main program seen as a separate thread ?

    I wanted to stop a GUI based program opening too fast because the splash screen wasn't seen for long enough.
    So I tried to use the Thread and Runnable classes within the GUI constructor.
    By trying different things, I got it to do as I wanted : a delay of 10 seconds before showing the program's GUI.
    But I don't understand why main is not seen as a separate thread and thus continue to make itself visible no matter what the delayThread status may be.
    // Constructor:
    public Hotel (int numberIn)
             // Create the time delay thread so that users may enjoy the splash !
             delayThread = new Thread(this);
             delayThread.run();
             // Initialise the number of rooms and the GuestList :        
            noOfRooms =  numberIn;
            guests  = new GuestList(noOfRooms);
            // Graphics settings:     
            setTitle("Hotel");     
            setLayout(new FlowLayout());
           // etc. etc.
           // etc. etc.
           setVisible(true);
        // A run method to delay the program opening:
        public void run()
             try
                  delayThread.sleep(10000);
             catch(InterruptedException ie)
                  ie.printStackTrace();
        }Now, maybe a better way to do this would be to move the setVisible statement from the constructor to the run method.
    Maybe there is an even better mechanism for producing a delay in a program's opening.
    But I'm still curious as to why the main thread was delayed by a delay in what is really an entirely separate thread.
    Any ideas ?
    Edited by: KonTiki on 16-Feb-2013 13:10
    Edited by: KonTiki on 16-Feb-2013 13:19
    Edited by: KonTiki on 16-Feb-2013 13:20
    Edited by: KonTiki on 16-Feb-2013 13:21
    Edited by: KonTiki on 17-Feb-2013 09:16

    Well, first of all calling a Thread object's run() method just runs the code in the same thread. It doesn't start a new thread -- that's what calling the start() method does.
    And the Thread.sleep() method is a static method, meaning "Make *this* thread sleep for X milliseconds". So calling it on another Thread object doesn't cause that thread to sleep, it causes the current thread to sleep.
    I suggest you should go through the concurrency tutorial from Oracle because you seem to be programming by guesswork here.

  • Does URLLoader load data in a separate thread?

    I understand the Flash and AS3 is single-threaded, at least at the user level.
    However, I would like to understand how asynchronous data loading is handled by the Flash player.
    For instance, if I run CPU-intensive code that runs beyond the normal frame (lets say it runs on ENTER_FRAME, and consumes 1/4 per call).  Does this leave any CPU cycles to load data from a URLLoader?
    If http loading is truly synchronous, right down to handling the TCP/IP stack, one would get horrible performance.
    In Windows programming, I can do http access asynchronously (in which case the Windows libraries are doing either input on a separate thread, or doing hardware-level interrupts to handle the data -- I provide an asynchronous callback that may be on its own thread).  Or, I can do synchronous download, in which case there will be hardware buffering, but my application is actively waiting for each buffer of data to be delivered by the hardware/OS combination.
    URLLoader is asynchronous, but what does that mean?  Does it mean that I can run the CPU and still download data?  Or, will my download speed slow to a crawl if my Flash application is under heavy CPU load?
    Understanding how this works will help me design my product better, which both uses a lot of CPU, and downloads a lot of data (to the bandwidth limit of the network, if possible).

    >>"no data handling can occur if the cpu is 100% occupied.  so, the download will slow/stop."
    Operating systems have pre-emptive multitasking, so if download were in another thread, it could still operate.
    My CPU has 4 cores.  So by 100% busy, I meant that I am getting close to maxing out the main thread of Flash, which only uses one core.
    >>data downloading being asynchronous means while data is downloading the cpu and your actionscript can do other things
    This is my question exactly.  Asynchronous can mean many things.  At the lowest layer, at least one "buffer" of data (who knows what size) has to be downloaded in a separate thread, or by hardware, or by the browser, etc.  Flash could have a background thread internally that grabs data from this buffer, and does something with it.  Or, Flash could rely on polling this buffer on the main thread in-between frames.  The last method would be bad, as it would rely on the user not using the complete CPU usage per frame.
    The real truth may be a combination of these two -- it may download in a background thread, but only up to some limit, at which point the Flash main thread has do internally grab it?
    >>but it is possible to have other actionscript tasks or flash animations interfere with downloading.
    My question is, how much care and feeding does the download require?  Does it work quite well by itself, and is rarely affected by AS3 CPU use, or is there a requirement to not use up all of the CPU per-frame in order for the download to proceed?  In my case, I may stretch my frames out to 1/4 second, as I do intensive CPU work.  Would this slow or stop my downloads?
    Thanks for the helpful reply -- I would love a bit more detail though.
    Also, I'm more likely to be using URLStream in my actual implementation.

  • Very slow JTextArea updates even as separate thread

    Hi,
    I am trying to report output of a dynamic stream as a JFrame that contains JTextArea. The module is part of my big SWING application. The problem is JTextArea only shows update after the stream is empty. I have tried the following things
    * Stream pocessed as separate thread.
    * Thread priority set to maximum.
    * function updateUI is called after a batch of lines have been written.
    Here's the code to activate the thread
    StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT",outputWindow);
    outputGobbler.start();Here's the code for StreamGobbler class with JTextArea and JFrame
    import java.util.*;
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    class StreamGobbler extends Thread
        InputStream is;
        String type;
        String thsContent;
        JTextArea outputWindow;
        StreamGobbler(InputStream is, String type,JTextArea dPane){
            this.is = is;
            this.type = type;
         outputWindow=dPane;
         thsContent=new String("");
        public void run(){
         int myMode=1;
         int lineCt=0;
         String myLineSep=new String(System.getProperty("line.separator"));
            try{
                InputStreamReader isr = new InputStreamReader(is);
                BufferedReader br = new BufferedReader(isr);
                String line=null;
                while ( (line = br.readLine()) != null){
              if(myMode==1){
                  setDisplayWindow();
                  myMode=2;
                 System.out.println(type + ">" + line);
              outputWindow.append(line+myLineSep);
              lineCt++;
              if(lineCt==10){
                  outputWindow.updateUI();
                  lineCt=0;
             if(myMode==2)
              outputWindow.updateUI();
         } catch (IOException ioe){
             ioe.printStackTrace(); 
        public void setDisplayWindow(){
         setPriority(MAX_PRIORITY);
         outputWindow=new JTextArea("output",80,300);
         JScrollPane scrollingArea1= new JScrollPane(outputWindow);
         scrollingArea1.setPreferredSize(new Dimension(440, 210));
         scrollingArea1.setMinimumSize(new Dimension(400, 200));
         scrollingArea1.setMaximumSize(new Dimension(1000, 500));
         outputWindow.setEditable(false);
         JFrame displayWindow=new JFrame("Display Window");
         displayWindow.setContentPane(scrollingArea1);
         displayWindow.pack();
         displayWindow.setVisible(true);
    }

    Thanks for your reply sir.
    JDialog won't work for me. I need a JComponent that lets incremental display of content (like append method used in JTextArea).
    Below is my example code that you can run and see what I am trying to do. In this example the lines generated by ping are very few. My application actually uses an exe file instead of ping command. The .exe generates few KB of output. I am trying to stream the output of this exe to JTextArea. I am sorry I am not able to provied the actual exe itself.
    The example given below works well as the JTextArea gets filled as the output is printed on the command prompt window. It is because of limited resource consumption by ping command. This does not happen with my .exe file. The JTextArea is filled only after the .exe file stops executing. The few hundred lines printed by the .exe file appears suddenly instead of a continuous manner (Although the System.out.println continued to print the output on the command prompt console continuously like the ping example below). Thus there is a delay between the console output and JTextArea when using my exe file.
    import java.util.*;
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    class StreamGobbler extends Thread
        InputStream is;
        String type;
        String thsContent;
        JTextArea outputWindow;
        StreamGobbler(InputStream is, String type){
            this.is = is;
            this.type = type;
         thsContent=new String("");
        public void run(){
         int myMode=1;
         int lineCt=0;
         String myLineSep=new String(System.getProperty("line.separator"));
            try{
                InputStreamReader isr = new InputStreamReader(is);
                BufferedReader br = new BufferedReader(isr);
                String line=null;
                while ( (line = br.readLine()) != null){
              if(myMode==1){
                  setDisplayWindow();
                  myMode=2;
                 System.out.println(type + ">" + line);
              ///          thsContent=thsContent.concat(line);
              outputWindow.append(line+myLineSep);
              ///          outputWindow.append();
              lineCt++;
              if(lineCt==1){
                  outputWindow.updateUI();
                  lineCt=0;
             if(myMode==2)
              outputWindow.updateUI();
         } catch (IOException ioe){
             ioe.printStackTrace(); 
        public void setDisplayWindow(){
         setPriority(MAX_PRIORITY);
         outputWindow=new JTextArea("output",80,300);
         JScrollPane scrollingArea1= new JScrollPane(outputWindow);
         scrollingArea1.setPreferredSize(new Dimension(440, 210));
         scrollingArea1.setMinimumSize(new Dimension(400, 200));
         scrollingArea1.setMaximumSize(new Dimension(1000, 500));
         outputWindow.setEditable(false);
         ///     JPanel myPanel=new JPanel();
         ///     myPanel.add(scrollingArea1);
         JFrame displayWindow=new JFrame("MASPIC Run Window");
         ///     displayWindow.setContentPane(myPanel);
         displayWindow.setContentPane(scrollingArea1);
         displayWindow.pack();
         displayWindow.setVisible(true);
        public static void main(String args[]) {
    try{           
                Runtime rt = Runtime.getRuntime();
                Process proc = rt.exec("ping localhost");
                // any error message?
                StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR");           
                // any output?
             ///            StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT",outputWindow);
                StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT");
                // kick them off
             ///            errorGobbler.start();
                outputGobbler.start();
                // any error???
                int exitVal = proc.waitFor();
                System.out.println("ExitValue: " + exitVal);       
            } catch (Throwable t){
                t.printStackTrace();
    }

  • How to make a function in separate thread

    i need to make a function that is running in a separate thread
    Thank's in advance

    Thank's
    but in my program i have a main class which is a server it runs forever.
    from the main class when i call a function it runs in a separate thread and returns the result to the callee and the main function continue it's work
    class server
    //this function when called must be in separate thread
    public int function(int x)
    //there could be wait here or sleep
    return x*2;
    public static void main(String[] args)
    // Run RMI server
    i hope u understand me!!!
    Thank's

Maybe you are looking for

  • Sub heading in ALV report

    Hi All,              is there any way for subheading in ALV report.       For Example:                           staff                               worker                                          L1 L2 R1 R2 R3 R4         w1 w2 w3 w4  w5 w6 thks sha

  • I am looking for a app that will allow me to build and form for staff review then log it back to a main computer across mutiple users

    Please help,  The app that I need is one that firstly build and set of question into a form,  then allow other staff member to fill in the answers and then generate a report back to a centre database for review.  Also within this app if it is able to

  • Validation error using flat files..VLD-2407

    Trying to build a simple flat file mapping to test out file locations and permissions at a new client and getting the following error: VLD-2407: SQL*Loader map must have a source file. OWB 10.2.0.3. I've added a filename for everything i could find i

  • How to search a topic in SAP Library

    All SAP Gurus, This is rather a simple problem, but I'm unable to find the solution for it. I'm using SAP Help library 'ECC6.0', we followed the following steps to search our desired topic (for example: procurment) 1. We click over 'SEARCH' tab 2. En

  • Display Chinese Language

    In the struts-config.xml I set <message-resources parameter="test.view.TestResources_zh_cn"/> The TestResources_zh_cn.properties file contains the Chinese characters for the keys. Next I go to the Internet Explorer to set the language to Chinese[zh-c