Assalomu alaykum, yordam.uz saytimizga xush kelibsiz.
Bu saytda o`zingizni qiziqtirgan savollarga javob olishingiz va o`z sohangiz bo`yicha savollarga javob berishingiz mumkin. Bizning Oilamizga a'zo bo`lganingiz uchun chuqur Minnatdorchilik bildiramiz !!!

C# da bir nechta thread

+1 ovoz
242 marta ko‘rilgan
so‘radi 25 yanvar, 18 SARVARBEK (355 bal)

StationForm (Windows Form) da global o'zgaruvchilar e'lon qilingan.
isconnectionfailedthread va thread oqimlarni ishga tushirganda IsWorking o'zgaruvchisining qiymati isconnectionfailedthreadda o'zgarsa threadda o'zgarmayapdi va aksincha.
Huddi alohida oqimlarda alohida yaratilgandek.IsWorking o'zgaruvchisini qanaqa qilib umumiy qilsam bo'ladi, yani bitta oqimda qiymat o'zgarsa, 2-oqimda ham o'zgarishi kerak.

  1.   public partial class StationForm : Form
  2.     {
  3.         Station Station;
  4.         public Thread thread;
  5.         Form1 form1;
  6.         Thread isconnectionfailedthread;
  7.         int isconnectionfailedthreadint;
  8.         int viewminutvalue;
  9.         bool isWorking;
  10.         public bool IsWorking
  11.         {
  12.             get { return isWorking; }
  13.             set
  14.             {
  15.                 bool t = value;
  16.                 if (t != isWorking)
  17.                 {
  18.                     isWorking = t;
  19.                     if (isWorking)
  20.                     {
  21.                         Station.treenode.ForeColor = Color.Green;
  22.                         statusStrip1.BackColor = Color.LightGreen;
  23.                     }
  24.                     else
  25.                     {
  26.                         Station.treenode.ForeColor = Color.Red;
  27.                         statusStrip1.BackColor = Color.Red;
  28.                         toolStripStatusLabel1.Text = "Last disconnect time: " + CurrentTime.ToString("dd/MM/yyyy HH:mm:ss");
  29.                         Station.seedlinkreader = null;
  30.                     }
  31.                     numberpacketfordatfiles++;
  32.                 }
  33.             }
  34.         }
  35. //Konstruktor
  36.     public StationForm(Station _station, Form1 f1)
  37.         {
  38.             InitializeComponent();
  39.             Station = _station;
  40.             form1 = f1;
  41.             StartStation();
  42.         }
  43.     public void StartStation()
  44.         {
  45.             Station.channel = "BHZ";
  46.             Station.start = SeedlinkReader.EMPTY;
  47.             //Station.start = "2017,12,13,14,00,00";
  48.             Station.end = SeedlinkReader.EMPTY;
  49.             //Station.end = "2018,12,13,14,00,00";
  50.             Station.maxRecords = 10;
  51.             Station.timeoutSeconds = SeedlinkReader.DEFAULT_TIMEOUT_SECOND;
  52.             Station.infoType = SeedlinkReader.EMPTY;
  53.             Station.ioutFile = SeedlinkReader.EMPTY;
  54.             Station.verbose = false;
  55.             Station.dos = null;
  56.             Station.file = new java.io.File(Station.stationname + ".log");
  57.             Station.out1 = new java.io.PrintWriter(Station.file);
  58.             IsWorking = false;
  59.             thread = new Thread(ForThread);
  60.             isconnectionfailedthread = new Thread(ForIsConnectionFailedThread);
  61.             isconnectionfailedthreadint = 0;
  62.             g = Graphics.FromImage(image);
  63.             UpdateGraphics();
  64.             thread.Start();
  65.             isconnectionfailedthread.Start();
  66.         }
  67. }

Shu joyini qanday to'g'rilasam bo'ladi?

Oldindan rahmat

1 ta javob

0 ovoz
javob berdi 29 yanvar, 18 m.kholmirzaev (164 bal)

Nima ish qilmoqchisiz? Formada oqimlarni ishlayotgan yoki ishlamayotganligi haqida ma'lumot chiqarmoqchimisiz?

Bu yuqorida siz keltirgan misolda o'zgarmayotganligini sababi oqimlar alohida alohida bajarilishidan. Forma ham bitta oqim. Oqimlar bir biri bn ma'lumot almashinishi uchun C# da alohida mexanizmlar bor. Mana bu linkda oqimlarni sinxsonizatsiyalashtirish haqida to'liq ma'lumot bor: https://docs.microsoft.com/ru-ru/dotnet/csharp/programming-guide/concepts/threading/thread-synchronization

izoh qoldirdi 31 yanvar, 18 SARVARBEK (355 bal)
Nima ish qilmoqchisiz? Formada oqimlarni ishlayotgan yoki ishlamayotganligi haqida ma'lumot chiqarmoqchimisiz? - Forma ichida ikkita alohida threadlarni ishga tushirgandim. Formda e'lon qilingan global o'zgaruvchilar ikkita threadda alohida bo'lib turuvdi. Ya'ni, o'sha o'zgaruvchilarning qiymati birinchi threadda o'zgarsa ham, ikkinchi threadda oldingi qiymati qolib ketyotgandi.

Rahmat javob uchun.

Assalomu alaykum, yordam.uz saytimizga xush kelibsiz.

Bu saytda o`zingizni qiziqtirgan savollarga javob olishingiz va o`z sohangiz bo`yicha savollarga javob berishingiz mumkin.

Bizning Oilamizga a'zo bo`lganingiz uchun chuqur Minnatdorchilik bildiramiz !!!

Telegram kanal YordamUzRss

...