Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace dino_test
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- //Omoguci stvaranje elementi (webbrowsera) iz drugih threadova (nije bas super rjesenje ali za ovaj slucaj je oke)
- CheckForIllegalCrossThreadCalls = false;
- if (!WBEmulator.IsBrowserEmulationSet())
- {
- WBEmulator.SetBrowserEmulationVersion();
- }
- }
- private void runBrowserThread()
- {
- var th = new Thread(() => {
- var br = new WebBrowser();
- br.DocumentCompleted += browser_DocumentCompleted;
- br.ScriptErrorsSuppressed = true;
- br.Navigate(new Uri("https://www.quotes.net/authors/Cometan"));
- Application.Run();
- });
- th.SetApartmentState(ApartmentState.STA);
- th.Start();
- }
- void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
- {
- var br = sender as WebBrowser;
- MessageBox.Show(br.DocumentText.ToString());
- Application.ExitThread();
- /*
- if (br.Url == e.Url)
- {
- MessageBox.Show(br.DocumentText.ToString());
- Application.ExitThread();
- }
- */
- }
- private void Button1_Click(object sender, EventArgs e)
- {
- int n = Int32.Parse(textBox1.Text);
- Thread[] threadovi = new Thread[n];
- for (int i=0; i<n; i++)
- {
- threadovi[i] = new Thread(runBrowserThread);
- //threadovi[i].SetApartmentState(ApartmentState.STA); //Zguglaj ovo, bez toga se nebre webbrowser u drugom threadu stvarato
- threadovi[i].Start();
- }
- //for (int i = 0; i < n; i++) threadovi[i].Join();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement