-1
private void Form2_Load(object sender, EventArgs e)
    {
        con1.Open();

        Form1 home = new Form1();
        home.MdiParent = this.MdiParent ;

        System.Timers.Timer timer1 = new System.Timers.Timer();
        Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyComputer)  + @"\\server1\KamalSingh\ScreenCaptures");
        t.Interval  = 500;
        t.Tick += new EventHandler(StartThread);
        t.Start();
     }


   System.Windows.Forms.Timer t = new  System.Windows.Forms.Timer();
   //Thread tt;   

   private static Bitmap bmpscreenshot;
   private static Graphics gfxscreenshot;

    void TakeScreenShot()
    {

        bmpscreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height,PixelFormat.Format32bppArgb);
        gfxscreenshot = Graphics.FromImage(bmpscreenshot );
        gfxscreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,Screen.PrimaryScreen.Bounds.Y,0,0,Screen.PrimaryScreen.Bounds.Size,CopyPixelOperation.SourceCopy );
        bmpscreenshot.Save(Environment.GetFolderPath(Environment.SpecialFolder.MyComputer) +@"\\server1\KamalSingh\ScreenCaptures\.bmp", ImageFormat.Png);
      //  tt.Abort();
    }

     protected  void StartThread(object sender, EventArgs e)
     {
         Thread th  = new Thread(new ThreadStart(TakeScreenShot));
         th.SetApartmentState(ApartmentState.STA );
         th.Start();
         Thread.Sleep(100);
         th.Join();

     }

プログラムの実行中に発生するこのエラーを修正したいと思います。エラーはしばらくすると発生します。

4

1 に答える 1

0

これを試して:

void TakeScreenShot()
{

    using(Bitmap bmpscreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height,PixelFormat.Format32bppArgb))
    {
        using(Graphics gfxscreenshot = Graphics.FromImage(bmpscreenshot))
        {
            gfxscreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,Screen.PrimaryScreen.Bounds.Y,0,0,Screen.PrimaryScreen.Bounds.Size,CopyPixelOperation.SourceCopy );
            bmpscreenshot.Save(Environment.GetFolderPath(Environment.SpecialFolder.MyComputer) +@"\\server1\KamalSingh\ScreenCaptures\.bmp", ImageFormat.Png);
        }
    }
}

お役に立てれば!

于 2012-09-24T21:32:28.677 に答える