Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7940795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:28:47+00:00 2026-06-03T23:28:47+00:00

I have a wpf application. During the running of the application, when I get

  • 0

I have a wpf application.
During the running of the application, when I get to some method I fire event which performs some operations . In this event I have to access to an instance of DLL that works with Database , and it throws exception which tells that another thread owns that object. What would be the best way to handle this?

//this is in the main thread - in MainWindow.cs - code behind
 MyDataBaseManager DB_manager = new MyDataBaseManager(connectionString);

//event handler
 void MainWindow_MyCustomEvent(object sender, MainWindow.MyCustomEventArgs e)
    {
        try
        {

            if (str1 == str2)
            {
                //getting exception when trying to perform this statement 
                DB_manager.UpdateTable(this.textBlock_MyTextBlock.Text, DateTime.Now, currenrUser);


                theNextstring = DB_manager.GetTheNextString();

                if (theNextstring != string.Empty)
                {
                    this.textBlock_theNextstring.Text = theNextstringף
                }

            }



        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "Error", MessageBoxButton.OKCancel, MessageBoxImage.Error);
        }
    }

when I compare two strings in the if statement, It doesn’t throw an exception , but when I want to use DB_manager or to use the UI components , I get the –

The calling thread cannot access this object because a different thread owns it.

Should I pass to the event a connection string and make a new instance in the object? Or there is another , better solution?

thanks…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T23:28:48+00:00Added an answer on June 3, 2026 at 11:28 pm

    the best way to do it is to use the Dispatcher.Invoke method …
    this.textBlock_theNextstring.Dispatcher.Invoke.

    Sample –
    http://social.msdn.microsoft.com/forums/en-US/wpf/thread/360540eb-d756-4434-86f9-a3449f05eb55

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF application in which i have to do a long running
I use some UserControls which get created and destroyed within my application during runtime
I have a wpf application which has combo box and multiple text boxes. On
I have a wpf application, which consumes wcf service. I wish to catch any
I have developed WPF application which contains the menuitem. I set background color to
My .NET 4 application uses the WPF TreeView which I have enhanced to enable
I have a very annoying exception which freeze my application thrown by WPF, when
I have a WPF C# application, to which I have to pass command line
In a WPF Application using XAML, I have 2 images, which needs to be
We have a WPF application which gets data from an Analysis Services Cube. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.