我有一个消息列表.每条消息都有一个类型.
public enum MessageType
{
Foo = 0,
Bar = 1,
Boo = 2,
Doo = 3
}
Run Code Online (Sandbox Code Playgroud)
枚举名称是任意的,无法更改.
我需要返回列表排序为:Boo,Bar,Foo,Doo
我目前的解决方案是创建一个tempList,按我想要的顺序添加值,返回新列表.
List<Message> tempList = new List<Message>();
tempList.AddRange(messageList.Where(m => m.MessageType == MessageType.Boo));
tempList.AddRange(messageList.Where(m => m.MessageType == MessageType.Bar));
tempList.AddRange(messageList.Where(m => m.MessageType == MessageType.Foo));
tempList.AddRange(messageList.Where(m => m.MessageType == MessageType.Doo));
messageList = tempList;
Run Code Online (Sandbox Code Playgroud)
我怎么能用IComparer做到这一点?
我正在尝试使用文本框来显示完成任务.基本上就像控制台应用程序将如何显示正在发生的事情.
但是,文本框中的文本仅在Window_Loaded_1完成后才更新,然后显示所有文本而不是实时显示.
xaml代码:
<Window x:Class="timelineTesting.Windows.CreateNewProject"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="CreateNewProject" Height="300" Width="579" Loaded="Window_Loaded_1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBox Text="{Binding Path=LogData, UpdateSourceTrigger=PropertyChanged}" />
</Grid>
Run Code Online (Sandbox Code Playgroud)
C#代码:
public partial class CreateNewProject : Window, INotifyPropertyChanged
{
private string _data;
public String LogData
{
get
{
return _data;
}
set
{
_data = value;
OnPropertyChanged("LogData");
}
}
public CreateNewProject()
{
InitializeComponent();
this.DataContext = this;
}
private void Window_Loaded_1(object sender, RoutedEventArgs e)
{
Task t = new Task(() => Directory.CreateDirectory(this.ProjectName));
LogData+="Starting new project creation...." + Environment.NewLine;
LogData += …Run Code Online (Sandbox Code Playgroud) 我正在绘制时间轴控件的标题.它看起来像这样:

我每行走0.01毫秒,所以对于10分钟的时间线我正在寻找60000行+ 6000个标签.这需要一段时间,约10秒.我想从UI线程中卸载它.我的代码目前是:
private void drawHeader()
{
Header.Children.Clear();
switch (viewLevel)
{
case ViewLevel.MilliSeconds100:
double hWidth = Header.Width;
this.drawHeaderLines(new TimeSpan(0, 0, 0, 0, 10), 100, 5, hWidth);
//Was looking into background worker to off load UI
//backgroundWorker = new BackgroundWorker();
//backgroundWorker.DoWork += delegate(object sender, DoWorkEventArgs args)
// {
// this.drawHeaderLines(new TimeSpan(0, 0, 0, 0, 10), 100, 5, hWidth);
// };
//backgroundWorker.RunWorkerAsync();
break;
}
}
private void drawHeaderLines(TimeSpan timeStep, int majorEveryXLine, int distanceBetweenLines, double headerWidth)
{
var currentTime = new TimeSpan(0, 0, …Run Code Online (Sandbox Code Playgroud) 我在应用程序上运行 dotTrace 的 ConsoleProfiler ( dotTrace doc ) 并不断收到一条消息:
"分析在 60.906 秒内成功完成
未收集任何快照”。
我错过了什么?
控制台输出:
C:\JetBrainsCLT>ConsoleProfiler.exe dotTrace_Config.xml snapshot.dtp
Console Profiler 2016.1 build 105.0.20160414.155338 Copyright (C) 2011-2015 JetBrains s.r.o.
...
Profiling is successfully finished in 60.906 seconds
No snapshots have been collected
Run Code Online (Sandbox Code Playgroud)
dotTrace_Config.xml:
<root>
<HostParameters type="LocalHostParameters" />
<Argument type="StandaloneArgument">
<Arguments IsNull="False">
</Arguments>
<FileName>C:\Sourcecode\Project\bin\Debug\Test.exe</FileName>
<WorkingDirectory>C:\Sourcecode\Project\bin\Debug</WorkingDirectory>
<Scope>
<ProcessFilters />
</Scope>
</Argument>
<Info type="PerformanceInfo">
<MeasureType>Sampling</MeasureType>
<MeterKind>Rdtsc</MeterKind>
<InjectInfo>
<SymbolSearch>
<SearchPaths />
</SymbolSearch>
<Scope>
<PatternFilters />
<DenyAttributeFilters />
</Scope>
</InjectInfo>
</Info>
<CoreOptions type="CoreOptions">
<CoreTempPath IsNull="False">
</CoreTempPath> …Run Code Online (Sandbox Code Playgroud) 我不知道我是否在失去理智,或者这是否可能.
顺便说一句,我没有使用任何标准库,所以这不依赖于语言,因此它为什么而不是stackoverflow.
我有两个时间段以int格式传递给我.
1st period-
Start Time:
End Time:
2nd period-
Start Time:
End Time:
Run Code Online (Sandbox Code Playgroud)
Int是从午夜开始的分钟,因此早上7点将是420分钟.
所以我想写的函数的一个例子是:
bool SpanMoreThan24Hours(int firstStartTime, int firstEndTime,
int secondStartTime, int secondEndTime)
{
....
}
Run Code Online (Sandbox Code Playgroud)
我甚至不确定这可以做到.
PS跨越午夜很好,但它没有必要.期间不能重叠.
So it could look like this:
420, 1140, 1260, 419
7am, 7pm, 9pm, 6:59am
- Valid
This would be valid since it doesn't span over 24 hours.
420, 1140, 1260, 421
7am, 7pm, 9pm, 7:01am
- Not valid
420, 60, 120, 419
7am, 1am,2am, 6:59am
- Valid
Run Code Online (Sandbox Code Playgroud)
我必须确保从第1期开始时间到第2期结束时间不超过24小时.
我有一个Class(称为'Foo'),它有一个System.Timers.Timer(称之为'myTimer').
Foo包装非托管非线程安全代码.
在myTimer.Elapsed我需要在Foo中使用Methods.
现在myTimer尝试在工作线程上使用Foo的方法,这是行不通的.
我需要回到包含Foo'Methods的线程.
我该如何做到这一点?仅供参考,Foo的方法是在非UI线程中.