반응형
스레드를 이용한 비동기 멀티스레딩
TitleSearch titleSearch = new TitleSearch();
ImageSearch imageSearch = new ImageSearch();
SemanticSearch semanticSearch = new SemanticSearch();
TitleSearch titleSearch = new TitleSearch();
ImageSearch imageSearch = new ImageSearch();
SemanticSearch semanticSearch = new SemanticSearch();
Task[] threads = new Task[]
{
//타이틀 검색 결과
new Task(() => resultTitleSearchXmlData=titleSearch.Operation(keyword)),
//시맨틱 검색 결과
new Task(() => resultSemanticSearchXmlData=semanticSearch.General(catgory,keyword)),
//이미지 검색결과
new Task(() => resultImageSearchXmlData=imageSearch.Operation(keyword))
};
new Task(() => resultTitleSearchXmlData=titleSearch.Operation(keyword)),
//시맨틱 검색 결과
new Task(() => resultSemanticSearchXmlData=semanticSearch.General(catgory,keyword)),
//이미지 검색결과
new Task(() => resultImageSearchXmlData=imageSearch.Operation(keyword))
};
for (int i = 0; i < threads.Length; i++)
{
threads[i].Start();
}
Task.WaitAll(threads);
또는
델리게이트를 이용한 비동기 멀티스레딩
//비동기 엔진 호출을 위한 메소드 선언
{
threads[i].Start();
}
Task.WaitAll(threads);
또는
델리게이트를 이용한 비동기 멀티스레딩
//비동기 엔진 호출을 위한 메소드 선언
public delegate XmlDocument SemanticDele(int? catgory, string keyword);
public delegate XmlDocument ImageDele(string keyword);
public delegate XmlDocument TitleDele(string keyword);
SemanticDele semanticDele = new SemanticDele(semanticSearch.General);
ImageDele imageDele = new ImageDele(imageSearch.Operation);
TitleDele titleDele = new TitleDele(titleSearch.Operation);
IAsyncResult semanticSearchResult = semanticDele.BeginInvoke(catgory, keyword, null, null);
IAsyncResult titleSearchResult = titleDele.BeginInvoke(keyword, null, null);
IAsyncResult imageSearchResult = imageDele.BeginInvoke(keyword, null, null);
//Do some other work on priamry thread..
resultTitleSearchXmlData = titleDele.EndInvoke(titleSearchResult);
resultImageSearchXmlData = imageDele.EndInvoke(imageSearchResult);
resultSemanticSearchXmlData = semanticDele.EndInvoke(semanticSearchResult);
public delegate XmlDocument ImageDele(string keyword);
public delegate XmlDocument TitleDele(string keyword);
SemanticDele semanticDele = new SemanticDele(semanticSearch.General);
ImageDele imageDele = new ImageDele(imageSearch.Operation);
TitleDele titleDele = new TitleDele(titleSearch.Operation);
IAsyncResult semanticSearchResult = semanticDele.BeginInvoke(catgory, keyword, null, null);
IAsyncResult titleSearchResult = titleDele.BeginInvoke(keyword, null, null);
IAsyncResult imageSearchResult = imageDele.BeginInvoke(keyword, null, null);
//Do some other work on priamry thread..
resultTitleSearchXmlData = titleDele.EndInvoke(titleSearchResult);
resultImageSearchXmlData = imageDele.EndInvoke(imageSearchResult);
resultSemanticSearchXmlData = semanticDele.EndInvoke(semanticSearchResult);
반응형
'Programming' 카테고리의 다른 글
mysql 백업(dump) 하기 (0) | 2012.05.25 |
---|---|
mssql alter table column (테이블 필드 수정, 삭제, 추가) 및 테이블명, 필드(컬럼)명 수정 (0) | 2011.11.07 |
https GET 결과 가져오기 (0) | 2011.10.06 |
IIS 5.1 접속 제한 늘리기 (0) | 2011.09.19 |