 |
|
อยากทราบวิธีการใช้งาน threading ใน VB 2008 ช่วยแนะนำหน่อย นะครับ เพิ่งหัดเรียน |
|
 |
|
|
 |
 |
|
มีอะไรส่งใส ถามได้ครับ หรือจะศึกษาเองได้ -> Thread
|
 |
 |
 |
 |
Date :
2011-12-14 16:07:42 |
By :
kanchen |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Imports System.Threading
Public Class FrmMornitorError
Private th As Thread
Private Sub _CheckDuplicate(ByVal _Table As String)
Call _Connect()
SB_Process("drop table tum_tempDoup purge")
Com = New OleDb.OleDbCommand(_Str, Conn)
Try
Com.ExecuteNonQuery()
Catch ex As Exception
End Try
SB_Process("create table tum_tempDoup as select a.* from erroredit a ," & _Table & " b where a.account_no=b.account_no and a.sub_a=b.sub_a and a.sub_b=b.sub_b and a.start_date=b.start_date and a.start_time=b.start_time")
Com = New OleDb.OleDbCommand(_Str, Conn)
Try
Com.ExecuteNonQuery()
Catch ex As Exception
End Try
SB_Process("delete from erroredit a where (a.account_no||a.sub_a||a.sub_b||a.start_date||a.start_time) in (select a.account_no||a.sub_a||a.sub_b||a.start_date||a.start_time from tum_tempDoup a)")
Com = New OleDb.OleDbCommand(_Str, Conn)
Try
Com.ExecuteNonQuery()
Catch ex As Exception
End Try
Conn.Close()
End Sub
'Sub Main(ByVal args As String())
' Dim t As New System.Threading.Thread(AddressOf ThreadStart)
' t.SetApartmentState(System.Threading.ApartmentState.STA)
' t.Start()
'End Sub
Private Sub _ProcessErrorCall(ByVal _Table As String, ByVal _Num As String)
Call _Connect()
SB_Process("INSERT INTO " & _Table & " SELECT a.BLOCK, a.account_no, a.sub_a, a.sub_b, a.start_date, a.start_time,a.caller_name, a.called_name, a.country, a.real_time, a.dur_charge,a.amount, a.call_type, a.ERROR_CODE, a.inc_route, a.out_route,a.sub_c, a.filename FROM erroredit a WHERE a.start_date >='" & Format(CDate(dpkFrom.Text), "dd/MM/yyyy") & "' and a.start_date <='" & Format(CDate(dpkTo.Text), "dd/MM/yyyy") & "' and a.LOCATIONB <> '***' AND SUBSTR (sub_a, 1, 4) IN (" & _Num & ")")
Com = New OleDb.OleDbCommand(_Str, Conn)
Try
Com.ExecuteNonQuery()
Catch ex As Exception
End Try
SB_Process(" delete from erroredit a where SUBSTR (sub_a, 1, 4) IN (" & _Num & ") and a.start_date >='" & Format(CDate(dpkFrom.Text), "dd/MM/yyyy") & "' and a.start_date <='" & Format(CDate(dpkTo.Text), "dd/MM/yyyy") & "' and a.LOCATIONB <> '***'")
Com = New OleDb.OleDbCommand(_Str, Conn)
Try
Com.ExecuteNonQuery()
Catch ex As Exception
End Try
Conn.Close()
End Sub
Private Sub btnFixError_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFixError.Click
End Sub
End Class
ลบกวนช่วยทำ Threading Code ด้านบนให้ดูหน่อยคณับ ไมรู้จะเลี่มต้นยังไง
|
 |
 |
 |
 |
Date :
2011-12-14 23:43:18 |
By :
Thipphakorn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (C#)
private void ThreadLoad()
{
Hashtable hst = new Hashtable();
hst.add("_Table ",aaaa);
hst.add("_Num",aaa);
hst.add("stLoad","_ProcessErrorCall");
// ประกาศ Thread ให้สมารถส่งค่า parameter ได้ โดยถ้าไม่ต้องการส่งก็ประกาศให้เป็น Thread TProcess = new(new ThreadStart());
Thread TProcess = new Thread(new ParameterizedThreadStart(ThreadChoose));
//กำหนดให้ Thread ทำงานแบบ Background
TProcess .IsBackground = true;
//เริ่มทำงาน แล้วส่งค่าไปให้ method ThreadChoose
TProcess .Start(Hst);
}
private void ThreadChoose(object stLoad)
{
//แปลงค่าจาก object เป็น Hashtable
Hashtable hstData = (Hashtable)stLoad;
if(hstData["stLoad"].toString() == "_ProcessErrorCall")
{
//ทำงานใน method _ProcessErrorCall
_ProcessErrorCall(hstData["_Table "].toString(), hstData["_Num"].toString());
}
}
พอดีเขียน vb ไม่ได้แล้วครับเอา แบบ c# ไปศึกษาดูแล้วกันครับ คำสั่งหลักของ Thread ที่ผมใช้ก็มีประมาณนี้ครับ
จิงๆมันมีเยอะกว่านี้ครับเอาแค่หลักที่ใช้ก่อนครับ
|
 |
 |
 |
 |
Date :
2011-12-15 09:28:15 |
By :
kanchen |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|