好吧,我已经创建了一个程序,它执行多个副本并将文本添加到文件中,其运行时间我所提出的是一个list_,用于存储大量密钥然后打印回来的过程结束,而不是有消息框加载这是我有创建一个全局列表并将其存储在其中的字符串形式多类
列表类。
public class Messageresult : Weaons
{
private List<string> elfenliedtopfan5 = new List<string>();
public List<string> _Message
{
get { return elfenliedtopfan5; }
set { elfenliedtopfan5 = value; }
}
}
和班多我把这个像这样
public void ShowMessage()
{
elfy1 = new Messageresult();
//MessageBox.Show(elfy1._Message.ToString());
update();
refreshlist();
var message = string.Join(Environment.NewLine, elfy1._Message);
MessageBox.Show(message + Environment.NewLine +
createa + Environment.NewLine + results);
elfy1._Message.Clear(); }
所以这是我在多个不同的类中使用,我使用继承 TIS类以上的称为武器。和我所有其他类继承武器,但
我有这样的问题,我有像我的雷枪类 某些类时,我称之为。
public void cliantfx()
{
elfy1 = new Messageresult();
string path = modcliant;
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
File.Copy(Properties.Settings.Default.root + "//raw//clientscripts//" + ModName + ".csc", path + ModName + ".csc");
MessageBox.Show(path);
}
if (File.Exists(path + ModName + ".csc"))
{
using (StreamReader elfenliedtopfan6 = new StreamReader((path + ModName + ".csc")))
{
string elfenliedtopfan6_program = elfenliedtopfan6.ReadToEnd();
if (elfenliedtopfan6_program.Contains(@"clientscripts\_thundergun::init();"))
{
//MessageBox.Show(@"clientscripts\_thundergun::init();" + "Already Added:");
refreshlist();
elfy1._Message.Add("clientscripts\\_thundergun::init();" + "Already Added:");
}
if (!elfenliedtopfan6_program.Contains(@"clientscripts\_thundergun::init();"))
{
elfenliedtopfan6.Dispose();
if (File.Exists(path + ModName + ".csc"))
{
{
string s = Environment.NewLine
+ @" clientscripts\_thundergun::init();";
string file = path + ModName + ".csc";
List<string> lines = new List<string>(System.IO.File.ReadAllLines(file));
int index = lines.FindLastIndex(item => item.Contains(@"clientscripts\_zombiemode_tesla::init();"));
if (index != -1)
{
lines.Insert(index + 1, s);//""
}
System.IO.File.WriteAllLines(file, lines);
MessageBox.Show("Added: " + s + "To " + ModName);
}
}
,正如你可以看到elfy1._message.Add(“文字在这里......”)
被称为武器,但是,当它执行寿这一点,只是给一个空白消息框,但是当我执行weapons_gsc它工作完全正常
我用的是相同的呼叫methord和showmessage()函数 武器
但在声音类thundergun类,它不会更新或一旦其执行
0显示所以即时通讯不知道如何我会去这个。
,因为它的工作原理下面显示weapons_gsc图像完全正常的结果
image of it working for weapons_gsc and weapons
你在看到底的声音一个我不得不做出一个propeties.setting.default.results
并提出它=声音alais只有一种方式,我可以让它显示在一个消息框中的结果。
每次编写新的Messageresult();时,都会创建该类的新实例。所以这不是一个“全局列表”,即使它的成员不是静态的,它只存在直到你创建一个新的实例。如果只有一个线程,只需在构造函数或字段初始值设定项中标记字段'readonly'并实例化一次。 – Groo
在雷霆队我有大约7个线程,我只是选择那个作为例子,因为那个类是一个大类,所以不想在这里发布整个事情,我将如何工作只读(因为我的主要类是武器.cs并且被所有其他类继承。 –
这个类根本没有同步,所以它对于多线程访问是不安全的。你确定这应该是一个*字段*吗?因为你要么:1)想要一个单一的实例,它可以被多个线程同时使用(在这种情况下,您需要一个**单线程安全实例**或2)希望每个方法/线程都有一个单独的**局部变量**,该变量将在该范围的末尾转储。现在,您将'elfy1'字段设置为指向一个新实例(在某个方法的开始处),然后对其列表进行变异(从其他方法),最后从某处读取其内容。 – Groo