首先为我在短时间内重复的问题道歉..
我再次在其他地方使用类有问题,我的错误是:
Error 1 Cannot declare a variable of static type 'umEdition.Program'
Error 2 Cannot create an instance of the static class 'umEdition.Program'
我的代码是:
using DBNUpdater;
using System;
using System.IO;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Windows.Forms;
using System.Reflection;
namespace umEdition
{
internal static class Program
{
[CompilerGenerated]
private static bool BackingField;
private static bool openUpdater = false;
private static ProgressDialog pdialog;
private static bool updaterFinished = false;
private static void _core_Completed(object sender, EventArgs e)
{
updaterFinished = true;
Completed = true;
}
private static void _core_Failed(object sender, FailedEventArgs e)
{
MessageBox.Show(e.Exception.ToString(), "loader", MessageBoxButtons.OK, MessageBoxIcon.Hand);
Completed = true;
updaterFinished = false;
}
private static void _core_StatusChanged(object sender, StatusChangedEventArgs e)
{
if (e.StatusText == "Downloading")
{
if (pdialog != null)
{
pdialog.Line1 = e.StatusText;
pdialog.Line2 = e.DetailedStatus + string.Format(" ({0}%)", Math.Round(e.ExactPercentage, 1));
pdialog.Line3 = " ";
pdialog.Value = (uint)(e.ExactPercentage * 10.0);
}
if (!Completed)
{
openUpdater = true;
Completed = true;
}
}
}
[MTAThread]
private static void Main1()
{
string[] strArray = new string[] { "a", "b", "c", "d", "e" };
Random random = new Random();
string str = strArray[random.Next(0, strArray.Length)];
Completed = false;
var icon = new NotifyIcon();
icon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location);
icon.Text = "PlusGamer - starting";
icon.Visible = true;
Core core = new Core();
core.CacheLocation = Environment.CurrentDirectory;
core.WebCacheServer = string.Format("http://mysite.com/", str);
core.LocalCacheServer = "";
core.WantedCaches = new string[] { "anyfiles" };
core.EnableUploading = false;
core.StatusChanged += new EventHandler<StatusChangedEventArgs>(Program._core_StatusChanged);
core.Failed += new EventHandler<FailedEventArgs>(Program._core_Failed);
core.Completed += new EventHandler<EventArgs>(Program._core_Completed);
core.Start();
var time = DateTime.UtcNow;
var shown = false;
while (!Completed)
{
System.Threading.Thread.Sleep(1);
var newTime = DateTime.UtcNow;
var diff = newTime - time;
if (diff.TotalMilliseconds > 2000)
{
if (!shown)
{
icon.ShowBalloonTip(2500, "any text ;)", ToolTipIcon.Info);
shown = true;
}
}
}
if (openUpdater)
{
Completed = false;
pdialog = new ProgressDialog(IntPtr.Zero);
pdialog.Title = "loading";
pdialog.Maximum = 0x3e8;
pdialog.ShowDialog(new ProgressDialog.PROGDLG[1]);
}
while (!Completed)
{
Thread.Sleep(1);
if ((pdialog != null) && pdialog.HasUserCancelled)
{
core.Kill();
return;
}
}
if (updaterFinished)
{
if (!File.Exists("chrome.exe"))
{
//MessageBox.Show("Cannot find iw4m.exe");
MessageBox.Show("OPSS!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
int promptValue = Prompt.ShowDialog("lol", "lol2");
}
icon.Visible = false;
icon.Dispose();
}
public static class Prompt
{
public static int ShowDialog(string text, string caption)
{
Form prompt = new Form();
prompt.Width = 500;
prompt.Height = 100;
prompt.Text = caption;
Label textLabel = new Label() { Left = 50, Top = 20, Text = text };
prompt.ShowDialog();
return 1;
}
}
public static bool Completed
{
[CompilerGenerated]
get
{
return BackingField;
}
[CompilerGenerated]
set
{
BackingField = value;
}
}
}
}
然后我在这里尝试使用上述代码中的类程序:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Program update = new Program();
}
但我有错误吗?!再次感谢您的帮助。