Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
245
Reporting on sepeate thread (system.threading.thread)
posted

Has anyone else had issues when printing a xamDataGrid and trying to show progress bar whilst exporting / printing / previewing on separate thread? Im getting the thread exception error (Exception has been thrown by the target of an invocation.) (The calling thread cannot access this object because a different thread owns it.)

Thanks

  • 525
    Suggested Answer
    posted

    You need to get yourself back into the UI thread before showing the window... here is some code to do that:

     

    private delegate void DelegateLaunch();

    private void LaunchWindowInUIThread()
    {
        if (_myWindow != null && _myWindow.Dispatcher.Thread != Thread.CurrentThread)
        {
            _myWindow.Dispatcher.BeginInvoke(new DelegateLaunch(LaunchWindow));
        }
        else
        {
            LaunchWindow();
        } 
    }

    private void LaunchWindow()
    {
        _myWindow.ShowDialog();
    }