다양한 형태와 다양한 스레드를 기반으로하는 응용 프로그램에 문제가 있습니다. 응용 프로그램이 종료되기 전에 스레드가 닫히지 만 응용 프로그램을 100 % 정확하게 종료 할 수는 없습니다.C# 응용 프로그램이 닫히지 않습니다.
때때로 프로세스가 계속 작동하지만 아무 것도 표시되지 않습니다 (Form
또는 심지어 Thread
초). 나는 문제가, program.cs에이 거의 확실하다고 생각, 그래서 여기에 코드
private static Process old;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
XmlConfigurator.Configure();
if (PriorProcess() != null)
{
try
{
old.Kill();
}
catch (Exception ex)
{
MessageBox.Show("Ja existe uma instancia do SpotLight em execucao.", "Aviso");
return;
}
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Support());
}
public static Process PriorProcess()
{
Process curr = Process.GetCurrentProcess();
Process[] procs = Process.GetProcessesByName(curr.ProcessName);
foreach (Process p in procs)
{
if ((p.Id != curr.Id) && (p.MainModule.FileName == curr.MainModule.FileName))
{
old = p;
return p;
}
}
return null;
}
New Support()
응용 프로그램에 표시의 첫 양식을 붙여 넣을 수 있습니다.
이
는 스레드에 대한 코드입니다 :private void check_calls()
{
while (stop==false)
{
string actualTime = DateTime.Now.ToString("T");
connection = new MySqlConnection(ConnectionString);
MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand();
msqlCommand.Connection = connection;
msqlCommand.CommandText = "Select cd.uniqueid,sup.timespan from contactCenterDevel.cc_cdr_support_pending sup, vboxZon.cdr cd WHERE sup.phone=cd.src AND cd.finish=0 AND cd.accountcode='serviin' AND cd.duration >0 AND cd.lastapp='Vxml' ORDER BY cd.calldate DESC LIMIT 1";
try
{
connection.Open();
MySql.Data.MySqlClient.MySqlDataReader msqlReader = msqlCommand.ExecuteReader();
while (msqlReader.Read())
{
int timespanCompare = convertTimetoSecs(msqlReader.GetString(1));
int actualtimeCompare = convertTimetoSecs(actualTime);
if (timespanCompare < actualtimeCompare)
{
updateFlagCDR(msqlReader.GetString(0));
}
}
}
catch (Exception er)
{ MessageBox.Show("Mysql actions error: " + er); }
finally
{ connection.Close(); }
Thread.Sleep(10000);
}
}
플래그 "정지"내 로그 아웃 기능을 true로 변경 될 때이 하나가 중지됩니다. 이미 "thread.sleep"에 주석을 달았지만 문제는 여전히 나타납니다.
* 메인 애플리케이션 스레드 *가 종료되는 방식에 대한 코드를 게시 할 수 있습니까? – GregRos
당신이 할 수있는 일은 : 응용 프로그램이 환상 모드에있을 때, VS를 실행하고 프로세스에 연결합니다. 그런 다음 실행을 일시 중지하고 스레드를 표시합니다 (디버그 메뉴 => windows => threads). 시작한 스레드가 있습니까 (직접 또는 간접적으로)? – Kek
삽입 된 DB 연결 스레드 코드 – AndreLucas13