Hi all, i wanna ask you about thread in webservice, i have two main threads that will handle some process.
Example : Thread A = > Handle process 1.
Thread B = > Handle process 2.
When the message come into my webservice, Thread A will process the message (this process is inserting data into database).
Simultanously, Thread B always check is exist data in database, if exist Thread B will read some messages in the database and processing it tobe a meaningful data. As your information, Thread B will never be die, may be like a "daemon" i think :-\ . So, when Thread A has finished its process, Thread B is always run eventhough the data in database is not exist. But unfortunately, while Thread B is still run, sudden an error has occured : "Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack".
I have tried to restart the iis but it doesn't work.. :~ It has made me like a stupid boy... arrrgghhh... :mad:
This is my code :
[WebMethod]
public void MethodOAQ(byte[] messages, string memberCode)
{
CController cc = new CController(memberCode, messages, 6);
BasicController bc = new BasicController();
Thread oThread1 = new Thread(() => cc._SaveMsgToTbl_());
Thread oThread2 = new Thread(() => bc._BackgroundWorker(null));
oThread2.IsBackground = true;
oThread1.Start();
oThread2.Start();
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Threading;
using System.ComponentModel;
public class CController
{
CExecutorQuery ceq;
private readonly string memberid = string.Empty;
private readonly byte[] content = null;
private readonly int type_msg;
public CController(string memberid, byte[] content, int type_msg)
{
this.memberid = memberid;
this.content = content;
this.type_msg = type_msg;
}
public int SaveMsgToTbl()
{
ceq = new CExecutorQuery();
int kondisi = 0;
try
{
ceq.INSERT_DATA_T_INCOMING_MSGS(Encoding.UTF8.GetString(content), DateTime.Now.ToString("yyyyMMdd"), memberid, "NEW", type_msg);
kondisi = 1;
}
catch
{
kondisi = 0;
}
return kondisi;
}
public void _SaveMsgToTbl_()
{
ceq = new CExecutorQuery();
ceq.INSERT_DATA_T_INCOMING_MSGS(Encoding.UTF8.GetString(content), DateTime.Now.ToString("yyyyMMdd"), memberid, "NEW", type_msg);
}
}
internal sealed class BasicController
{
private CReaderConfig crc;
private ClassPesan cp;
private CExecutorQuery ceq;
public void _BackgroundWorker(object sender)
{
if (IS_THREAD_ALIVE.Equals(false))
{
IS_THREAD_ALIVE = true;
ThreadPool.QueueUserWorkItem(new WaitCallback(_Process), null);
}
}
private void _Process(object sender)
{
crc = new CReaderConfig();
ceq = new CExecutorQuery();
IDictionary<string, IDictionary<int, string>> KAMUS = new Dictionary<string, IDictionary<int, string>>();
while (true)
{
System.Threading.Thread.Sleep(1000);
foreach (string membercode in crc.List_Payment_Bank())
{
KAMUS.Add(membercode, ceq.COLLECT_DATA_T_INCOMING_MSG(membercode, "NEW"));
}
foreach (KeyValuePair<string, IDictionary<int, string>> dict in KAMUS)
{
foreach (KeyValuePair<int, string> pair in dict.Value)
{
try
{
cp = new ClassPesan(Encoding.UTF8.GetBytes(pair.Value), dict.Key);
cp.PROCESS_DATA();
ceq.DO_UPDATE_DATA_T_INCOMING_MSGS(dict.Key, pair.Key);
}
catch (Exception ex)
{
continue;
}
}
}
}
}
NB : I think this has nothing to do with the "Response.Redirect" because of this issue to talk about webservice.
Would you please help me ?? :confused: