小编Sea*_*n B的帖子

如何创建Windows注册表观察程序?

如何使用.Net创建Windows注册表观察程序应用程序,

我希望此应用程序在值更改时观察所有注册表挂钩并触发事件,此事件将告知该旧值和新值.

那可能吗?怎么样?只需要想法或从哪里开始

.net c# vb.net registry

11
推荐指数
1
解决办法
1万
查看次数

使用WPF中的TaskBarItemInfo获取Win 7任务栏中的进度条

有没有人在进行ProgressValue时有一个WPF示例通过可用的枚举状态更新ProgressState?

我有以下代码将我的进度值绑定为从0到1运行:

<Window.TaskbarItemInfo>
    <TaskbarItemInfo Description="An app with a taskbar info description" 
                     ProgressValue="{Binding Count}" ProgressState="Normal"/>
</Window.TaskbarItemInfo>
Run Code Online (Sandbox Code Playgroud)

但是,从NoneNormalNone或其他流程的好方法是什么:None-Normal-Paused-Normal-None.上面的代码显示左侧的进度条为0%,然后以100%(1)结束.我想我可以将它与转换器绑定到我的ViewModel的另一个属性,但是想看看是否有人有任何更流畅的解决方案.

谢谢!

wpf taskbar windows-7 progress-bar

8
推荐指数
2
解决办法
6238
查看次数

如何从实体序列化为json?

我正在尝试将(Entity Framework 6)实体序列化为json.通过AsNoTracking()方法序列化之前我确保条目在内存中但是我得到一个错误,因为它无法从条目中引用的另一个表接收值.

Inner Exception: When an object is returned with a NoTracking merge option, Load can only be called when the EntityCollection or EntityReference does not contain objects.

Exception: JsonSerializationException:  Error getting value from 'TABLE_X' on 'System.Data.Entity.DynamicProxies....
Run Code Online (Sandbox Code Playgroud)

码:

List<Location> locations = new DbContext().Locations.Where(x => x.Type == 1).Take(5).AsNoTracking().ToList();
string s = JsonConvert.SerializeObject(locations, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
Run Code Online (Sandbox Code Playgroud)

我想要做的就是返回一个序列化实体的字符串.我不担心其他对象,仅仅是位置实体.

当我尝试处理连接然后json序列化我收到错误: The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.

我只想序列化我的列表,我不想返回/序列化任何外来依赖项.

c# entity-framework jsonserializer entity-framework-6

8
推荐指数
1
解决办法
4086
查看次数

C#GroupBy - 创建多个分组级别

鉴于以下课程:

public class Transaction
{
    public string Category { get; set; }
    public string Form { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

如何获得按CategoryForm?分组的事务分组?

基本上我希望它输出如下:

Category 1
    Form 1
        Transaction1
        Transaction2
        Transaction3
        ...
    Form 2
        Transaction1
        Transaction2
        Transaction3
        ...
Category 2
    Form 1
        Transaction1
        Transaction2
        Transaction3
        ...
    Form 2
        Transaction1
        Transaction2
        Transaction3
        ...
Run Code Online (Sandbox Code Playgroud)

c# linq group-by

6
推荐指数
2
解决办法
5632
查看次数

将CancellationToken传递给Task.Factory.StartNew()的目的是什么

在下面的代码中,a 作为第二个参数CancellationToken传递给.StartNew(,)方法,但只能Action通过lambda中的闭包来使用.那么,通过.StartNew(,)方法的第二个参数传递令牌的目的是什么?

var cts = new CancellationTokenSource();
var token = cts.Token;
Task.Factory.StartNew(() => 
{
    while (true)
    {
        // simulate doing something useful
        Thread.Sleep(100);
    }
}, token);
Run Code Online (Sandbox Code Playgroud)

task-parallel-library cancellation .net-4.5 cancellation-token

6
推荐指数
2
解决办法
462
查看次数

.ToListAsync()vs .ToList()+ Task.Run

我有一个WPF应用程序.

数据从存储库传递到ViewModel.检索数据的更好方法是什么:

方法1:

在存储库中:

public List<LogDetail> GetLogsOfTypeForCase(int caseId, LoggType logType)
    {
        using (var ctx = new SidraEntitiesNoChangesDetection())
        {
            var logs = (from l in ctx.Loggs
                where l.log_fk_caseid == caseId && l.log_operation == logType.ToString()
                select new LogDetail()
                {
                    ColumnName = l.log_columnname,
                    DateAndTime = l.log_dateandtime,
                    IdentificationDetail = l.log_identificationDetail,
                    NewValue = l.log_new_value,
                    OldValue = l.log_old_value,
                    TableName = l.log_tablename,
                    UserCode = l.User.usr_code
                }).ToList();

            return logs;
        }
    }
Run Code Online (Sandbox Code Playgroud)

在ViewModel中:

await Task.Run(
            () =>
            {
                if (false == this.CancellationTokenSource.IsCancellationRequested)
                {
                    this.CaseLogs = this.dataAdapter.GetLogsOfTypeForCase(this.CaseId, LoggType.S);
                }

            }, …
Run Code Online (Sandbox Code Playgroud)

c# wpf async-await

4
推荐指数
1
解决办法
5326
查看次数

如何使用AutoFixture创建SortedList <Tkey,TValue>

我尝试SortedList<,>使用AutoFixture 创建一个,但它创建了一个空列表:

var list = fixture.Create<SortedList<int, string>>();
Run Code Online (Sandbox Code Playgroud)

我想出了以下产生物品,但有点笨重:

fixture.Register<SortedList<int, string>>(
  () => new SortedList<int, string>(
    fixture.CreateMany<KeyValuePair<int,string>>().ToDictionary(x => x.Key, x => x.Value)));
Run Code Online (Sandbox Code Playgroud)

它不是通用的(强烈键入intstring).我有两个不同TValue SortedLists的创造.

有更好的建议吗?

c# unit-testing autofixture

4
推荐指数
1
解决办法
105
查看次数

如何保持断言失败数据

我正在使用VS2013/CodedUI,在我的[TestMethod]中我声明如下:

Assert.IsTrue(String.Equals(logo.GetModifiedBy(), "Vendor2"));
Run Code Online (Sandbox Code Playgroud)

这在我的测试用例中如预期的那样失败,但输出中的消息如下所示,有没有办法报告用于比较的数据?我搜索但没有找到太多

Message: Assert.IsTrue failed
Run Code Online (Sandbox Code Playgroud)

c# mstest coded-ui-tests

1
推荐指数
1
解决办法
202
查看次数