Custom Search

วันศุกร์ที่ 18 พฤษภาคม พ.ศ. 2555

การ stop port serial และหยุด Thread ไม่ให้โปรแกรมค้าง

การ stop port serial และหยุด Thread ไม่ให้โปรแกรมค้าง ไปลอกเขามาอีกทีแต่จำเวปไม่ได้แล้ว

private void Form1_FormClosing(object sender, FormClosingEventArgs e)


{

      if (serialPort1.IsOpen)

    {

          e.Cancel = true; //cancel the fom closing
          Thread CloseDown = new Thread(new ThreadStart(CloseSerialOnExit)); //close port in new thread to avoid hang

         CloseDown.Start();
    }

}

private void CloseSerialOnExit()

{
try

{
      serialPort1.Close(); //close the serial port
}
catch (Exception ex)

{
MessageBox.Show(ex.Message); //catch any serial port closing error messages
}
this.Invoke(new EventHandler(NowClose)); //now close back in the main thread
}

private void NowClose(object sender, EventArgs e)

{

this.Close(); //now close the form

}

วันศุกร์ที่ 6 เมษายน พ.ศ. 2555

แก้ เข้า device and printer windows 7 ไม่ได้

1.อาจเป็นเพราะอุปกรณ์บางตัวมีปัญหา ลองถอดออกดูแล้ว restart ใหม่
2.ไป stop service->Printer Spooler ดู แล้วเข้าใหม่สังเกตุอุปกรณ์ที่มีปัญหาแล้วถอดมันออกซะ
อย่าลืม start service คืนด้วยนะ

อีกวิธีไปเจอในเว็บเลยเอามาฝาก

Make sure that all printers are unplugged from your PC during this
time:
Click Start,
type "Services.msc" (without the quotation marks) in the Search box and
press Enter.
Double-click
"Printer Spooler" in the Services list.
Click Stop
and click OK.
Click Start,
type "%WINDIR%\system32\spool\printers" in the Start Search box and press
Enter, delete all files in this folder.
Click Start,
type "Services.msc" (without the quotation marks) in the Start Search box
and press Enter.
Double-click
"Printer Spooler" in the Services list.
Click on
Start. In the Startup Type list, make sure that "Automatic" is
selected and click OK. After that, head to the
Control Panel. Go to Administrative Tools. Go to Print
Management.
Expand Print Servers
Expand your PC
Click on Drivers
Delete anything related to an actual driver for this printer
Click on Printers
Delete the Printer if it is listed. If you receive errors trying
to remove it, let me know and we will need to do more.If not, reboot
your PC and attempt to open Devices and Printers again.