IAsyncResult ar = request.BeginGetResponse(GetAsyncResponse, new object[] {request, id});
private void GetAsyncResponse(IAsyncResult result)
{
object[] params = (object[])result.AsyncState;
HttpWebRequest request = (HttpWebRequest)params[0];
int id = (int)params[1];
// process here
}
Hata:
System.InvalidOperationException: Cross-thread operation not valid: Control ‘xlabel1′ accessed from a thread other than the thread it was created on. at System.Windows.Forms.Control.get_Handle at System.Windows.Forms.Control.set_WindowText at System.Windows.Forms.Control.set_Text at System.Windows.Forms.Label.set_Text at tester.MainForm.test in c:\Users\tester\Documents\SharpDevelop Projects\tester\tester\MainForm.cs:line 48 at System.Threading.ThreadHelper.ThreadStart_Context at System.Threading.ExecutionContext.Run at System.Threading.ThreadHelper.ThreadStart
Çözüm:
//Add code :
CheckForIllegalCrossThreadCalls = false;
thread1.Start();
Regex örneği yaratmak için System.Text kütüphanesini çağırmanız gerekiyor.
//.. string aranandesen = ".* zuzu.*[\r\n]+.*[\r\n]+.*[\r\n]+.*[\r\n]+.*[\r\n]+.*<a href="\">.*"; Regex arananRegex = new Regex(aranandesen); MatchCollection benimMatchCollection = arananRegex.Matches(yazi); string bulunan; foreach (Match benimMatch in benimMatchCollection) { bulunan = benimMatch.Groups[1].ToString(); } //.. </a>
Msdn deki örnek kod dosyada düzenli ifadedeki deseni arıyor…
<a href="\">StreamReader sr = new StreamReader(filename); string input; string pattern = @"\b(\w+)\s\1\b"; while (sr.Peek() >= 0) { input = sr.ReadLine(); Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase); MatchCollection matches = rgx.Matches(input); if (matches.Count > 0) { Console.WriteLine("{0} ({1} matches):", input, matches.Count); foreach (Match match in matches) Console.WriteLine(" " + match.Value); } } sr.Close(); </a>
Referans bağlantı:
http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.aspx