here is the code which looking for a folder and search some strings
which
are taken from a database called as marka[] a want to search those
string
very as possible which thread
thanks
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Threading;
using System.IO;
using System.Text;
using System.Data.OleDb;
using System.Text.RegularExpressions;
namespace Spider
{
/// <summary>
/// Summary description for Stringara.
/// </summary>
public class Stringara
{
private Hashtable m_file=new Hashtable();
/// <summary>
/// URL's that are waiting to be processed.
/// </summary>
private SpiderForm m_spiderForm;
private Queue m_workload=new Queue();
private Thread m_thread1;
enum Status { STATUS_FAILED, STATUS_SUCCESS,
STATUS_QUEUED };
private bool m_quit;
private Spider m_spider1;
String[] marka=new string[1500];
ArrayList flist=new ArrayList();
public void reset()
{
m_file = new Hashtable();
m_workload = new Queue();
m_quit = false;
}
public bool Quit
{
get
{
return m_quit;
}
set
{
m_quit = value;
}
}
public void folderlist()
{
string fldr=@"C:\temp\rt";
//System.Windows.Forms.MessageBox.Show(fldr);
DirectoryInfo dir = new DirectoryInfo(fldr);
FileInfo[] files = dir.GetFiles("*.html");
string fnm;
foreach(FileInfo fi in files)
{
//flist.Add(fi.Name);
fnm=fi.Name;
m_file.Add(fnm.ToString(),Status.STATUS_QUEUED);
//System.Windows.Forms.MessageBox.Show(fi.Name);
m_workload.Enqueue(fnm);
}
}
//public Queue marka=new Queue();
public void keyword()
{
string str="Provider =Microsoft.Jet.OLEDB.4.0 ;
Data
Source=..\\..\\Employee.mdb";
string cmd = "SELECT Keyword from KeyQ" ;
OleDbConnection con = new OleDbConnection ( str
) ;
OleDbCommand com = new OleDbCommand ( cmd, con )
;
con.Open();
int i=0;
OleDbDataReader r = com.ExecuteReader ( ) ;
while ( r.Read ( ) )
{
marka[i]=r[0].ToString();
i++;
}
con.Close ( ) ;
}
public void Start(int threads)
{
folderlist();
//reset();
keyword();
for(int i=1;i<threads;i++)
{
ThreadStart ts = new
ThreadStart( this.find);
m_thread1= new Thread(ts);
//m_thread.Priority=ThreadPriority.Highest;
m_thread1.Start();
}
}
public void find()
{
int m_threadCount=1;
while(m_threadCount<m_workload.Count)
{
//Monitor.Enter(this.m_thread1);
//Monitor.Pulse(this.m_thread1) ;
string str="";
string line=null;
string
str1=@"C:\temp\rt\"+m_workload.Dequeue().ToString( );
string path = @"C:\Documents and
Settings\Rustem\Desktop\csspider\csspider\keyword. txt";
//string lPattern = "(tayyip|erdoğan)";
StreamReader sr =new
StreamReader(str1,System.Text.Encoding.GetEncoding ("windows-1254"));
while ((line = sr.ReadLine()) != null)
{
str+=line+"\r\n";
}
//System.Windows.Forms.MessageBox.Show(str1);
string lPattern1 = ">(?:(?<c>[^<]+))";
Regex rx = new Regex(lPattern1,
RegexOptions.IgnoreCase |
RegexOptions.Compiled );
StringBuilder sb = new StringBuilder();
Match mt;
for ( mt = rx.Match(str); mt.Success; mt
= mt.NextMatch() )
{
sb.Append(
mt.Groups["c"].ToString() );
sb.Append( " " );
}
string spure=sb.ToString();
for (int i = 0; i <=1000; i++)
{
string
lPattern="("+marka[i].ToString()+")";
RegexOptions ro = new
RegexOptions();
ro = ro |
RegexOptions.IgnoreCase;
ro = ro |
RegexOptions.Multiline;
Regex re = null;
MatchCollection mc = null;
re = new Regex(lPattern, ro);
mc = re.Matches(spure);
if (mc.Count>0)
{
using (StreamWriter sw =
File.AppendText(path))
{
// Add some text
to the file.
sw.WriteLine(str1);
sw.WriteLine(mc.Count.ToString());
sw.WriteLine(marka[i].ToString());
}
}
//System.Windows.Forms.MessageBox.Show(mc.Count.ToSt ring());
}
m_threadCount++;
}
}
}
}>