... zdravim pani ... nedavno som zacal s C# takze vacsie skusenosti zrovna nemam. Prave sa snazim pochopit multithreading vo formulari. Verim tomu ze svojou otazkou a prikladom pomozem aj inym, takze ak mozete niekto najst riesenie na moj problem bolo by
to super. Problem je ten ze na rozdiel od konzolovej aplikacie kde je threading pomerne jednoducho aplikovatelny, vo formulari nedokazem updatnut textbox z ineho threadu ako z toho v ktorom bol texbox vytvoreny. Mam priklad:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace Threading_Example_1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void countDown1()
{
for (int i = 20000; i < 30000; i++)
{
textBox1.Text = i.ToString();
textBox1.Refresh();
}
}
private void countDown2()
{
for (int i = 0; i < 10000; i++)
{
textBox2.Text = i.ToString();
textBox2.Refresh();
}
}
private void button1_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
}
}
}
... formular Form1 obsahuje dva textboxy a tri butony (textBox1, texBox2, button1, button2 a button3). Predstavujemm si to tak ze "buton3" (popripade Form1_load) odstartuje odpocitanie v oboch textboxoch
nezavisle na sebe pricom textBox1 je updatovany funkciou
countDown1 a texBox2 zase funkciou countDown2.
Rad by som do toho este zakomponoval funkcionalitu kde button1 zabezpeci zastavenie odpoctu v
textBox1 a button2 zastavi odpocet v textBox2 ...
... ak by sa niekomu chcelo na to pozriet pouzite prosim Vas tento kod do ktoreho vlozite svoj update. Cim jednoduchsie riesenie tym lahsie na pochopenie principu ... dufam ze som sa nevyjadril zmatene a nepresne :) ...
Vdaka za pomoc.
[Reakcia]