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 7964289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:50:56+00:00 2026-06-04T05:50:56+00:00

I want to change a Form control property from a process thread event fire

  • 0

I want to change a Form control property from a process thread event fire in a class, I have the following code but I received this exception:

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

Code:

public partial class main : Window
{        
   public main()
   {
      InitializeComponent();
   }

   public void change()
   {
      label1.Content = "hello";
   }

   private void button1_Click(object sender, RoutedEventArgs e)
   {
      nmap nmap = new nmap(this);
      nmap.test("hello");
   }
}

class nmap
{
    private main _frm;
    private Process myprocess;

    public nmap(main frm)
    {
       _frm = frm;
    }

    public void test(object obj)
    {
        string s1 = Convert.ToString(obj);
        ProcessStartInfo startInfo = new ProcessStartInfo();
        myprocess = new Process();
        myprocess.StartInfo.FileName = "C:\\nmap\\nmap.exe";
        myprocess.EnableRaisingEvents = true;
        myprocess.Exited += new EventHandler(myProcess_Exited);

        myprocess.Start();
    }

    private void myProcess_Exited(object sender, System.EventArgs e)
    {
       try
       {
          _frm.change();
       }
       catch{}
    }
}

Please help me on this, I think delegate invoke must be work

My project is a WPF C# project.

answer is:

class nmap
    {
        private main _frm;
        private Process myprocess;


        public nmap()
        {

        }
        public nmap(main frm)
        {
            _frm = frm;
        }
        public void test(object obj)
        {
            string s1 = Convert.ToString(obj);
            ProcessStartInfo startInfo = new ProcessStartInfo();
            myprocess = new Process();
            myprocess.StartInfo.FileName = "C:\\nmap\\nmap.exe";
            //myprocess.StartInfo.CreateNoWindow = true;
            myprocess.EnableRaisingEvents = true;
            //myprocess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            myprocess.Exited += new EventHandler(myProcess_Exited);
            myprocess.Start();

        }

        private void myProcess_Exited(object sender, System.EventArgs e)
        {
            try
            {
                String s;
                s = "hello";
                _frm.Dispatcher.Invoke(_frm.USD, new Object[] { s });
            }
            catch{}
        }

    }

 public partial class main : Window
    {
        public delegate void UpdateStatusDelegate(string value);
        public UpdateStatusDelegate USD;

        public main()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            USD = new UpdateStatusDelegate(this.AddString);

        }
        private void AddString(String s)
        {
            label1.Content = s;

        }
        public void change()
        {
            label1.Content = "hello";
        }


        private void button1_Click(object sender, RoutedEventArgs e)
        {
            nmap nmap = new nmap(this);
            nmap.test("hello");

        }
}
  • 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-04T05:50:57+00:00Added an answer on June 4, 2026 at 5:50 am

    You can not touch any UI element from any threads other than the thread that owns the object. To achieve this you can wrap the call in a Invoke method like this:

    delegate void UpdateStatusDelegate (string value);
    
    private void UpdateStatus(string value)
    {
        if (InvokeRequired)
        {
            // We're not in the UI thread, so we need to call BeginInvoke
            BeginInvoke(new UpdateStatusDelegate(UpdateStatus), new object[]{value});
            return;
        }
        // Must be on the UI thread if we've got this far
        statusIndicator.Text = value;
    }
    

    in WPF world, you could get the same thing by using Dispatcher.Invoke method.

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

Sidebar

Related Questions

I want change following javascript code to jquery code, How is it? With done
So I have a main form with 3 controls whose Enable property I want
I have a Decorator Control class which I want to collect all the validation
I have a single form window application now I want to change the form
I want to change form attributes with JQuery. In other browsers it works fine,
I want a form where user can change password. I am able to encrypt
i have many div's with the same background image and i want change this
I have a class derived from TextBox in C#. I override OnClick method to
I have created a form in Visual Studio 2010 and set its size property
I have a form (let's call it parent form), from which another always on

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.