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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:54:16+00:00 2026-06-14T14:54:16+00:00

I have just started to learn windows application development, and we have been given

  • 0

I have just started to learn windows application development, and we have been given self learn project to develop one windows application. I am trying to create the application to send email. I have created a class MsgSender.cs to handle that. When I call that class from main form I am getting the following error

System.InvalidOperationException was unhandled.

Error Message–>

Cross-thread operation not valid: Control ‘pictureBox1’ accessed from a thread other than the thread it was created on.`

The stacktrace is as follows:

System.InvalidOperationException was unhandled
Message=Cross-thread operation not valid: Control 'pictureBox1' accessed from a thread other than the thread it was created on.
Source=System.Windows.Forms
StackTrace:
   at System.Windows.Forms.Control.get_Handle()
   at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
   at System.Windows.Forms.Control.set_Visible(Boolean value)
   at UltooApp.Form1.sendMethod() in D:\Ultoo Application\UltooApp\UltooApp\Form1.cs:line 32
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
InnerException: 

Code:

private void btnSend_Click(object sender, EventArgs e)
    {
        pictureBox1.Visible = true;
        count++;
        lblMsgStatus.Visible = false;
        getMsgDetails();
        msg = txtMsg.Text;

        Thread t = new Thread(new ThreadStart(sendMethod));
        t.IsBackground = true;
        t.Start();
    }

    void sendMethod()
    {
        string lblText = (String)MsgSender.sendSMS(to, msg, "hotmail", uname, pwd);
        pictureBox1.Visible = false;
        lblMsgStatus.Visible = true;
        lblMsgStatus.Text = lblText + "\nFrom: " + uname + " To: " + cmbxNumber.SelectedItem + " " + count;
    }
  • 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-14T14:54:18+00:00Added an answer on June 14, 2026 at 2:54 pm

    You can access Form GUI controls in GUI thread and you are trying to access outside GUI thread that is the reason for getting exception. You can use MethodInvoker to access controls in the GUI thread.

    void sendMethod()
    {
        MethodInvoker mi = delegate{
           string lblText = (String) MsgSender.sendSMS(to, msg, "hotmail", uname, pwd);
           pictureBox1.Visible = false;
           lblMsgStatus.Visible = true;
           lblMsgStatus.Text = 
                 lblText + "\nFrom: " + uname + 
                 " To: " + cmbxNumber.SelectedItem + " " + count;
       }; 
    
       if(InvokeRequired)
           this.Invoke(mi);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just started learning python version 3 and trying to create a file
I just started to learn windows azure and have I have exceeded the cache
I have just started to learn the Play 2.0 Framework. The one thing I
I have just started to learn how to code iOS apps. I have made
I have just started learning Rails, is it required for me to learn CoffeeScript
we have just started using a git account of our Django website project so
I have just started implementing ISet 's instead of IList 's in my project
I have just started trying to make a simple game with XNA 3.1 to
I have just started to learn the very basics of Java programming. Using a
I have just started to learn about the pros of foreign keys in database

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.