无论如何,c#VS Express 2012控制台应用程序立即关闭

时间:2016-06-23 18:57:22

标签: c# winforms

最近,为了恶作剧我的兄弟,我已经看过这个视频叫做#34;醉酒PC":https://www.youtube.com/watch?v=48k9eyVsC-M

我有c#的经验,我不难理解代码并编写代码。好的,让我们谈谈。

我的CODE工作得很好,它可以完成我想做的一切(作为控制台应用程序)但是当我转到我的项目属性并将输出类型更改为" Windows应用程序"并运行它,它立即关闭。

看过该视频的人知道,如果将其更改为Windows应用程序,则可以隐藏该应用程序。

我已尝试添加:Console.Read();if (System.Diagnostics.Debugger.IsAttached) Console.ReadLine();,但这些都不起作用,它会立即关闭。如果需要代码,我会将其粘贴到此处,即使它很长。

感谢您提前提供任何帮助。

代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Windows.Forms;
using System.Media;
using System.Drawing;

namespace DrunkPC
{
    class Program
    {
        public static Random _random = new Random();

        static void Main(string[] args)
        {
            Console.WriteLine("DrunkPC Prank Application by: Cupid (get pranked bruv)");

            Thread drunkMouseThread = new Thread(new ThreadStart(DrunkMouseThread));
            Thread drunkKeyboardThread = new Thread(new ThreadStart(DrunkKeyboardThread));
            Thread drunkSoundThread = new Thread(new ThreadStart(DrunkSoundThread));
            Thread drunkPopupThread = new Thread(new ThreadStart(DrunkPopupThread));

            drunkMouseThread.Start();
            drunkKeyboardThread.Start();
            drunkSoundThread.Start();
            drunkPopupThread.Start();

            Console.Read();

            drunkMouseThread.Abort();
            drunkKeyboardThread.Abort();
            drunkSoundThread.Abort();
            drunkPopupThread.Abort();
        }

        public static void DrunkMouseThread()
        {
            int moveX = 0;
            int moveY = 0;

            Console.WriteLine("DrunkMouseThread started");
            while (true)
            {
                moveX = _random.Next(20) - 10;
                moveY = _random.Next(20) - 10;
                Cursor.Position = new System.Drawing.Point(Cursor.Position.X + moveX, Cursor.Position.Y + moveY);
                Thread.Sleep(50); 
            }
        }
    }
}

2 个答案:

答案 0 :(得分:0)

鉴于你有Windows Application作为项目输出,我建议将主方法更改为:

static void Main(string[] args)
{
    Console.WriteLine("DrunkPC Prank Application by: Cupid (get pranked bruv)");

    Thread drunkMouseThread = new Thread(new ThreadStart(DrunkMouseThread));
    Thread drunkKeyboardThread = new Thread(new ThreadStart(DrunkMouseThread));
    Thread drunkSoundThread = new Thread(new ThreadStart(DrunkMouseThread));
    Thread drunkPopupThread = new Thread(new ThreadStart(DrunkMouseThread));

    drunkMouseThread.Start();
    drunkKeyboardThread.Start();
    drunkSoundThread.Start();
    drunkPopupThread.Start();

    // this one makes the trick
    while (true)
    {
        Thread.Sleep(100);
    }
}

一旦启动应用程序 - 没有显示任何窗口,鼠标会疯狂直到应用程序被杀

答案 1 :(得分:0)

添加以下行:

- (IBAction)pinchLayer:(UIPinchGestureRecognizer *)gestureRecognizer {

  static CGPoint lastPoint;
  static CGFloat lastScale;

  if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
    lastScale = 1.0;
    lastPoint = [gestureRecognizer locationInView:self.containerView];
  }

  // Scale
  CGFloat scale = 1.0 - (lastScale - gestureRecognizer.scale);
  [[gestureRecognizer view].layer setAffineTransform:
   CGAffineTransformScale([[gestureRecognizer view].layer affineTransform],
                          scale,
                          scale)];
  lastScale = gestureRecognizer.scale;

  // Translate
  CGPoint point = [gestureRecognizer locationInView:self.containerView];
  [[gestureRecognizer view].layer setAffineTransform:
   CGAffineTransformTranslate([[gestureRecognizer view].layer affineTransform],
                              point.x - lastPoint.x,
                              point.y - lastPoint.y)];
  lastPoint = [gestureRecognizer locationInView:self.containerView];

}
到最后。它会暂停,直到你按下回车。