سوال: مشکل در رباط تلگرام

ساخت وبلاگ
سلام و وقت بخیر
دوستان منبا یه رباط تلگرام نوشتم ولی برای وارد کردن متن ارسالی کاربر در تکست باکس ، به تکست باکسم ایراد میگیره و نمیإاره مقادیر رو در تکس باکس وارد کنم
اما در مسیج باکش ایرادی نمیگیره
ممنون میشم راهنماییم کنید

Telegram.Bot ورژن 10 استفاده کردم

اینم ارورش:


System.InvalidOperationException: 'Cross-thread operation not valid: Control 'textBox1' accessed from a thread other than the thread it was created on.'

System.InvalidOperationException occurred
HResult=0x80131509
Message=Cross-thread operation not valid: Control 'textBox1' 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.set_WindowText(String value)
at System.Windows.Forms.TextBoxBase.set_WindowText(St ring value)
at System.Windows.Forms.Control.set_Text(String value)
at System.Windows.Forms.TextBoxBase.set_Text(String value)
at System.Windows.Forms.TextBox.set_Text(String value)
at WindowsFormsApp1.Form1.GetUpdates() in C:UsersNPdocumentsvisual studio 2017ProjectsWindowsFormsApp1WindowsFormsApp1Fo rm1.cs:line 40
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.RunInternal(Exec utionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

اینم کد برنامه ام

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;

namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
Telegram.Bot.TelegramBotClient bot = new Telegram.Bot.TelegramBotClient("376*************** ******QkI");

Thread a;
public Form1()
{
InitializeComponent();
}

public void GetUpdates()
{
int offset = 0;
while(true)
{
Telegram.Bot.Types.Update[] updates = bot.GetUpdatesAsync(offset).Result;
foreach (var update in updates)
{
offset = update.Id + 1;
if (update.Message == null)
continue;

var from = update.Message.From.Username;
var textt = update.Message.Text;
long chatId = update.Message.Chat.Id;

textBox1.Text = chatId.ToString();

}

}
}

private void button1_Click(object sender, EventArgs e)
{
bot.SendTextMessageAsync("357935583", "salam");
}

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

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
try { a.Abort(); }
catch { }
}
}
}

برنامه نویس...
ما را در سایت برنامه نویس دنبال می کنید

برچسب : نویسنده : محمد رضا جوادیان programers بازدید : 121 تاريخ : دوشنبه 1 خرداد 1396 ساعت: 3:41