I have code running in a loop and it's saving state based on the current time. Sometimes this can be just milliseconds apart, but for some reason it seems that DateTime.Now will always return values of at least 10 ms apart even if it's only 2 or 3 ms later. This presents a major problem since the state i'm saving depends on the time it was saved (eg recording something) My test co
我的代码运行在一个循环中,并且基于当前时间保存状态。 有时候这可能只是几毫秒,但由于某些原因,即使仅仅2或3毫秒后,DateTime.Now总会返回至少10毫秒的值。 这是一个主要问题,因为我保存的状态取决于保存的时间(例如记录某些内容) 我的测试代码每10毫秒返回一个值: public static void Main() { var dt1 = DateTime.Now; System.Threading.Thread.Sleep(2); var dt2 = DateTime.Now; // On my mach
I want to create a looping connection check task (that is started after connection are started) both these function work but I have no clue on how to restart a task that was previously executed. Basically this is what i want to achieve: create task loop I can only start tasks directly, any attempt to create a task and execute it later failed. Also restarting a previously executed task fails
我想创建一个循环连接检查任务(在连接启动后启动)这两个函数都可以工作,但我不知道如何重新启动之前执行的任务。 基本上这是我想要实现的: 创建任务循环 我只能直接启动任务,任何尝试创建任务并稍后执行都会失败。 还重新启动先前执行的任务失败。 任何人都可以帮助我,是否有可能实现我的目标? 如果是的话,这是正确的方向,还是我做结构错误? 这让我烦恼几天,任何帮助或提示将不胜感激。 class Program {
I tried to create a multithreaded dice rolling simulation - just for curiosity, the joy of multithreaded progarmming and to show others the effects of "random results" (many people can't understand that if you roll a laplace dice six times in a row and you already had 1, 2, 3, 4, 5 that the next roll is NOT a 6.). To show them the distribution of n rolls with m dice I created this
我试图创建一个多线程的骰子滚动模拟 - 只是为了好奇心,多线程化的前进的喜悦,并向其他人展示了“随机结果”的效果(许多人无法理解,如果你连续六次掷骰子掷骰子,你已经有1,2,3,4,5,下一卷不是6.)。 为了向他们展示m个骰子的n个卷的分布,我创建了这个代码。 那么,结果是好的,但即使我为每个骰子创建一个新的任务程序运行单线程。 多线程将是合理的,以模拟6百万或更多骰子的“数百万”重播,因为结束时间将快速增长。
private async void button1_Click(object sender, EventArgs e) { await BackupFile(); } public async Task BackupFile() { await Task.Run(() => { for (var i = 0; i < partCount; i++) { upload(FilePart);//how to creat a new task at here //i don't want to wait here, i want to upload all part at same time } //wait here. //if total part got 10, then how to wai
private async void button1_Click(object sender, EventArgs e) { await BackupFile(); } public async Task BackupFile() { await Task.Run(() => { for (var i = 0; i < partCount; i++) { upload(FilePart);//how to creat a new task at here //i don't want to wait here, i want to upload all part at same time } //wait here. //if total part got 10, then how to wai
In my program I'm starting parallel tasks one by one (http requests), doing it far ahead of any actual results those tasks can return. It looks like while (continueTaskSwarming == true) { Task.Run(() => Task()); } Of course that way I have way more tasks scheduled than can be processed, so when I cancel them through cancellation token, it takes a lot of time to just cancel them all
在我的程序中,我逐个开始并行任务(http请求),在任何可以返回的实际结果之前执行。 看起来像 while (continueTaskSwarming == true) { Task.Run(() => Task()); } 当然,我有更多的任务可以处理,因此当我通过取消标记取消它们时,需要很长时间才能取消它们 - 它们都是按计划完成的,因此它们必须在可以运行之前实际运行被取消。 我如何组织任务创建,以便始终只有有限的一堆任务可以运行,新任务只有在他们有一
I need some help with handling Tasks. I have an XML String which is deserialized into a class. The class itself contains a property, eg rssProvider which is set to an unique value like MSN or YAHOO. However there can be multiple values delimited with an , in this field. I am using this deserialized class instance in multiple Tasks. However the function which gets called in this task can onl
我需要一些处理任务的帮助。 我有一个反序列化成一个类的XML字符串。 这个类本身包含一个属性,例如rssProvider,它被设置为像MSN或YAHOO这样的唯一值。 但是,在此字段中,可以有多个用分隔符分隔的值。 我在多个任务中使用这个反序列化的类实例。 然而,在这个任务中调用的函数只能使用一个rssProvider值,所以我对该字符串和创建该任务的foreach循环都进行了拆分。 在任务本身中,我调用的函数需要完整的对象,但需要
I am making a first attempt at playing with the new Tasks, but something is happening that I don't understand. First, the code, which is pretty straight-forward. I pass in a list of paths to some image files, and attempt to add a task to process each of them: public Boolean AddPictures(IList<string> paths) { Boolean result = (paths.Count > 0); List<Task> tasks = new
我正在尝试玩新的任务,但发生了一些我不明白的事情。 首先,代码非常简单。 我传递一些路径到一些图像文件,并尝试添加一个任务来处理它们中的每一个: public Boolean AddPictures(IList<string> paths) { Boolean result = (paths.Count > 0); List<Task> tasks = new List<Task>(paths.Count); foreach (string path in paths) { var task = Task.Factory.StartNew(() =&g
I have this piece of code: int i = 0; foreach(var tile in lib.dic.Values) { var ii = i; var t = tile; Button b = new Button( () = > { MainStatic.tile = t; } ); Checkbox c = new Checkbox( () = > { lib.arr[ii].b = !lib.arr[ii].b; } ); i++; } While the above code works as it should, this piece below: int i = 0; foreach(var tile in lib.dic.Values) { Button b = new But
我有这段代码: int i = 0; foreach(var tile in lib.dic.Values) { var ii = i; var t = tile; Button b = new Button( () = > { MainStatic.tile = t; } ); Checkbox c = new Checkbox( () = > { lib.arr[ii].b = !lib.arr[ii].b; } ); i++; } 虽然上面的代码正常工作,但下面这段代码: int i = 0; foreach(var tile in lib.dic.Values) { Button b = new Button( () = > { MainStatic.ti
I got a simple question to ask. Just Check below code and the question is in the end at the result of code. I hope you guys can help me.. file inventory.cs using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.UI; public class inventory : MonoBehaviour { public List<item> tmp = new List<item> (); public item itema; itemDat
我有一个简单的问题要问。 只需检查下面的代码,问题最终是代码的结果。 我希望你们能帮助我.. 文件inventory.cs using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.UI; public class inventory : MonoBehaviour { public List<item> tmp = new List<item> (); public item itema; itemDatabase database; // Use this for initializatio
I just wrote my first C# program. It's a simple piece of code which solves quadratic equations. It works with some functions (such as -6x2-6x+12) perfectly, while with others, (4x2-20x+25) it exhibits what I suspect are rounding errors. I'm completely new to C#, and I can't see an problems; would someone be able to help me debug this code? using System; using System.Collection
我只写了我的第一个C#程序。 这是一个解决二次方程的简单代码。 它可以完美地与一些函数(如-6x2-6x + 12)一起工作,而其他函数(4x2-20x + 25)则表现出我怀疑的舍入误差。 我对C#完全陌生,并且看不到问题; 有人能够帮助我调试此代码吗? using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication7 { class Progra