我Stopwatch在C#项目中得到了一些令人困惑的结果.请考虑以下代码:
static void Main(string[] args)
{
byte[] myEventArray = GetEventByteArrayFromDatabase();
byte[] myEventItemsArray = GetEventItemByteArrayFromDatabase();
uint numEvents = 1000;
uint numEventItems = 1000;
Stopwatch sw1 = Stopwatch.StartNew();
TestFunction(ref myEventArray, numEvents, ref myEventItemsArray, numEventItems);
sw1.Stop();
float timeTakenInSeconds = (float)sw2.ElapsedTicks / Stopwatch.Frequency;
Console.WriteLine("Total time: " + timeTakenInSeconds + " seconds. ");
}
static void TestFunction(ref byte[] EventArray, uint numEvents, ref byte[] EventItemArray, uint numEventItems)
{
Calculator calc = new Calculator();
calc.Test(EventArray, numEvents, EventItemArray, numEventItems);
}
Run Code Online (Sandbox Code Playgroud)
我跑了这个,得到大约0.2秒的时间.现在考虑一下:
static void Main(string[] args)
{ …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 ASP.net MVC 将复杂的数据类型从一个进程发送到另一个进程。由于某种原因,接收端总是收到空白(零/默认)数据。
我的发送方:
static void SendResult(ReportResultModel result)
{
//result contains valid data at this point
string portalRootPath = ConfigurationManager.AppSettings["webHost"];
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(portalRootPath);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage resp = client.PostAsJsonAsync("Reports/MetricEngineReport/MetricResultUpdate", result).Result;
if (!resp.IsSuccessStatusCode) {
//I've confirmed this isn't happening by putting a breakpoint in here.
}
}
Run Code Online (Sandbox Code Playgroud)
我的接收方在不同的类中,在本地计算机上的不同进程中运行:
public class MetricEngineReportController : Controller
{
...
[HttpPost]
public void MetricResultUpdate(ReportResultModel result)
{
//this does get called, but
//all the guids in result are zero …Run Code Online (Sandbox Code Playgroud)