C#で通常メインループなど書くことは、ほぼないと思います。
メインループが必要とされるのは、ゲーム作成など一部のアプリケーションだと思われます。とりあえずメインループの基本的な書き方を記載します。
メインループ プログラム
using System;
using System.Windows.Forms;
static class MyMain
{
//< 60FPSで処理
private const int waitTimes = (int)(1000.0 / 60.0);
[STAThread]
static void Main()
{
Form01 MainForm = new Form01(); //< フォーム生成
MainForm.Show(); //< フォームの表示
int targetTimes = System.Environment.TickCount & int.MaxValue;
targetTimes += waitTimes;
while (MainForm.Created)
{
int tickCount = System.Environment.TickCount & int.MaxValue;
if (targetTimes <= tickCount)
{
// メインの処理
MainForm.RenderFps(targetTimes);
targetTimes = (targetTimes + waitTimes) & int.MaxValue;
}
System.Threading.Thread.Sleep(1); //< スリープ処理
Application.DoEvents(); //< Windowメッセージ処理
}
}
}
※Sleepは処理を停止させる処理ですが、CPUの負荷率等を下げるのに必要です。
サブプログラム
using System;
using System.Windows.Forms;
using System.Drawing;
public partial class Form01 : Form
{
private Label label1;
public Form01()
{
InitializeComponent();
}
public void RenderFps(int targetTimes)
{
label1.Text = targetTimes.ToString();
}
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(96, 137);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(92, 12);
this.label1.TabIndex = 0;
this.label1.Text = "";
//
// Form01
//
this.ClientSize = new System.Drawing.Size(395, 322);
this.Controls.Add(this.label1);
this.Name = "Form01";
this.Text = "表示フォーム";
this.ResumeLayout(false);
this.PerformLayout();
}
}