Demo entry 4099467

de

   

Submitted by anonymous on Mar 19, 2016 at 10:46
Language: C#. Code size: 6.0 kB.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Threading;

namespace Form2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            
        }

        private delegate void greet(object sender);
        greet Form1Greet;


        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            //if (MessageBox.Show(this, "Are you sure you want to stop making windows always on top?", "Always on top", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != System.Windows.Forms.DialogResult.Yes)
            //{
            //    e.Cancel = true;
            //}

        }

        private void ChineseGreet(object sender)
        {
            Console.WriteLine("你好");
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            greet delegate1 = null;
            delegate1 += ChineseGreet;

            delegate1("");
        }

        private void Settings1_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            MessageBox.Show("Changed");
        }


        private void Form1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Form1_Click");
        }

        private void Form1_VisibleChanged(object sender, EventArgs e)
        {
            Console.WriteLine("Form1_VisibleChanged");
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            //Console.WriteLine("timer1_Tick");
        }


        private void Form1_Shown(object sender, EventArgs e)
        {
            //this.Hide();
            //this.notifyIcon1.ShowBalloonTip(3000);
        }


        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
        {
            this.Show();
            //this.WindowState = FormWindowState.Normal;
        }

        private void Form1_Resize(object sender, EventArgs e)
        {
            if(this.WindowState == FormWindowState.Minimized)
            {
                this.Hide();
            }
        }

        private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void Exit()
        {
            if (MessageBox.Show(this, "Are you sure you want to stop making windows always on top?", "Always on top", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
            {
                this.Close();
                Application.Exit();
            }
        }


        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            e.Handled = true;
        }

        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            e.Handled = true;

        }

        private void Form1_KeyPress(object sender, KeyPressEventArgs e)
        {
            //e.Handled = true;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            object[] args1 = { 20 };
            object[] args2 = { 30 };
            object[] args3 = { 40 };
            object[] args4 = { 50 };

            //Console.WriteLine("button4_Click: Current Thread ID: {0}", Thread.CurrentThread.ManagedThreadId);
            //IAsyncResult asyncResult = this.BeginInvoke(new CalcSumEventHandler(this.CalcSum), args1);
            //long result = (long)this.EndInvoke(asyncResult);
            //Console.WriteLine(result);
            Console.WriteLine("Main Thread ID: {0}", Thread.CurrentThread.ManagedThreadId);


            new Thread(() =>
            {
                Console.WriteLine("Thread ID: {0}", Thread.CurrentThread.ManagedThreadId);
                this.BeginInvoke(new Action(() =>
                {
                    Console.WriteLine("Thread ID: {0}", Thread.CurrentThread.ManagedThreadId);
                    Console.WriteLine("hehe");
                }));
            }).Start();



        }

        public delegate void TestEventHandler(int i, int j);

        public delegate long CalcSumEventHandler(long topLimit);
        private void test2(int i, int j)
        {
            Console.WriteLine("test2");
            Console.WriteLine("test2: Current Thread ID: {0}", Thread.CurrentThread.ManagedThreadId);
        }

        private long CalcSum(long topLimit)
        {
            Console.WriteLine("Cal Thread ID: {0}", Thread.CurrentThread.ManagedThreadId);
            checked
            {
                long result = 0;
                for (int i = 0; i < topLimit; ++i)
                {
                    result += i;
                }
                return result;
            }
        }
        private void listView1_ItemChecked(object sender, ItemCheckedEventArgs e)
        {
            Console.WriteLine(e.Item.Checked);
            Console.WriteLine("HEHE\n");
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string temp = "Before";
            Console.WriteLine("Main Thread ID: {0}", Thread.CurrentThread.ManagedThreadId);
            listBox1.BeginInvoke(new Action(() =>
            {
                //Thread.Sleep(10000);
                Console.WriteLine("Inside BeginInvoke() Thread ID: {0}", Thread.CurrentThread.ManagedThreadId);
                this.listBox1.Items.Add(temp += "Invoke!" + Thread.CurrentThread.Name);
            }));
        }
    }
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).