نمایش نتایج 1 تا 4 از 4

نام تاپیک: اشکال در حل مشکل Cross-thread operation not valid

Threaded View

پست قبلی پست قبلی   پست بعدی پست بعدی
  1. #1

    Exclamation اشکال در حل مشکل Cross-thread operation not valid

    با سلام به اساتید ارجمند وقتی برنامه رو run میکنم با ارور An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
    Additional information: Cross-thread operation not valid: Control 'label1' accessed from a thread other than the thread it was created on. مواجه میشم.
    مشکل قطعه کد زیر چیه؟ با سپاس

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    ================================================== =============================================




    public partial class Form1 : Form
    {
    Telegram.Bot.Api bot = new Telegram.Bot.Api("337051512:AAGl5b088W1q-_9Z8_y2ZtF8tQ6UIeoszvg");
    Thread a;


    public Form1()


    {
    InitializeComponent();
    }


    public void Getupdates()
    {


    int offset = 0;
    while (true)
    {


    Telegram.Bot.Types.Update[] updates = bot.GetUpdates(offset).Result;




    foreach(var update in updates)
    {
    offset = update.Id + 1;
    if (update.Message == null)
    continue;
    var from = update.Message.From;
    var text = update.Message.Text;
    long ChatId = update.Message.Chat.Id;




    label1.Text = string.Format("sender : (0)\nText : (1)\nChatid): (2)",from,text,ChatId);




    }


    }




    }
    private void Form1_Load(object sender, EventArgs e)
    {
    a = new Thread(new ThreadStart(Getupdates));
    a.Start();




    }


    آخرین ویرایش به وسیله mranderson : سه شنبه 09 خرداد 1396 در 17:59 عصر

برچسب های این تاپیک

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •