반응형
string _SendUrl = "";
string _GetUrl = "";
bool _isMssiExit = true;
bool _isImoExit = true;

Thread thread = new Thread(new ThreadStart(GetWebPageWorker));
Thread thread2 = new Thread(new ThreadStart(GetWebPageWorker));

_SendUrl = ""; //초기화
_GetUrl = "";  //초기화

_SendUrl = "URL링크"
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();

//Wating Thread
while(_isMssiExit)
{
	if (_GetUrl.IndexOf("shipid:") > -1)
	{
		_isMssiExit = false;
		thread.Abort();
	}
	else if (_GetUrl == _SendUrl)
	{
		thread.Abort();

		_SendUrl = "URL링크"
		thread2.SetApartmentState(ApartmentState.STA);
		thread2.Start();
		thread2.Join();

		while (_isImoExit)
		{
			if(_GetUrl.IndexOf("shipid:") > -1)
			{
				_isMssiExit = false;
				_isImoExit = false;
				thread2.Abort();
			}
			else if (_GetUrl == _SendUrl)
			{
				throw new ArgumentNullException("오류");
			}
		}
	}
}

//URL 가져오는 함수
protected void GetWebPageWorker()
{
	using (WebBrowser browser = new WebBrowser())
	{
		//  browser.ClientSize = new Size(_width, _height);
		browser.ScrollBarsEnabled = false;
		browser.ScriptErrorsSuppressed = true;
		browser.Navigate(_SendUrl);

		// Wait for control to load page
		while (browser.ReadyState != WebBrowserReadyState.Complete)
		Application.DoEvents();

		_GetUrl = browser.Url.AbsoluteUri; //Redirct 한 URL
	}
}

+ Recent posts