小编svi*_*ick的帖子

等待CLGeocoder.GeocodeAddressAsync永远不会返回

我正在尝试测试Apple的前向地理编码服务的准确性,以涵盖我们的数据模型上的纬度/经度缺失或无效的罕见情况,但我们仍然知道物理地址.MonoTouch的提供CLGeocoder.GeocodeAddress(String, CLGeocodeCompletionHandler)以及GeocodeAddressAsync(String)但是当我打电话给他们的completionHandler不会被调用和异步方法永远不会返回.

我的应用程序日志中没有任何内容表明存在问题,并且将调用封装在try-catch块中并未显示任何异常.在项目选项中启用了地图集成.没有捕获网络流量(无论如何可能是SSL)我没有想法.

这是加载地标并尝试地理编码地址的代码:

    private void ReloadPlacemarks()
    {
        // list to hold any placemarks which come back with empty/invalid coordinates
        List<ServiceCallWrapper> geoList = new List<ServiceCallWrapper> ();

        mapView.ClearPlacemarks ();

        List<MKPlacemark> placemarks = new List<MKPlacemark>();
        if (serviceCallViewModel.ActiveServiceCall != null) {
            var serviceCall = serviceCallViewModel.ActiveServiceCall;
            if (serviceCall.dblLatitude != 0 && serviceCall.dblLongitude != 0) {
                placemarks.Add (serviceCall.ToPlacemark ());
            } else {
                // add it to the geocode list
                geoList.Add (serviceCall);
            }
        }

        foreach (var serviceCall in serviceCallViewModel.ServiceCalls) {
            if (serviceCall.dblLatitude …
Run Code Online (Sandbox Code Playgroud)

c# core-location xamarin.ios async-await xamarin

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

如何使用动态构造对方法的调用

嗨,我有一个包含很多类的命名空间,所有这些都有一个方法Destroy(int id)我想用动态词调用该方法.

这是我的例子:

public bool DeleteElement<T>(T tElement)
{
    Type t = typeof(T);

    dynamic element = tElement;
    var id = element.Id;

    //until here everything is fine
    //here I want to say 
    (namespace).myClassName.Destroy(id);
    //the name of  myClassName is like t.ToString()
}
Run Code Online (Sandbox Code Playgroud)

我可以避免命名空间,包括在顶部使用.我的想法是使用动态调用静态方法,而不是反射,请看Destroy是T的静态方法.我需要像这样的东西T.Destroy(id)

c# c#-4.0 dynamictype

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

操作setter避免null

通常我们有:

public string code { get; set; }
Run Code Online (Sandbox Code Playgroud)

如果最终有人将代码设置为空,我需要避免空引用异常

我试试这个主意……有什么帮助吗?

public string code { get { } set { if (code == null) { code = default(string); }}}
Run Code Online (Sandbox Code Playgroud)

.net c# properties

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

Process Stream类不支持写入

我正在尝试使用流类向进程写入内容.我正在使用.net 4.5.然而,似乎写作不是支持.

Process.StandardOutput.BaseStream.CanWrite 
Run Code Online (Sandbox Code Playgroud)

返回false.

Process Stream类不支持写入是真的吗?

c# stdout process

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

什么是'int'类型函数的返回变量(sql查询函数)

下面我声明一个巫婆类型的函数是'int'.我为sql查询声明了这个函数,它将int作为输出.在这里,我必须返回一些东西.但我无法理解我在这个'int'类型函数中返回的内容.

    public int Login(LoginClass loginClassObj)
    {
        string connectionString = @"Data Source=localhost;Initial Catalog=LoginTest;Integrated Security=True";
        SqlConnection connection = new SqlConnection(connectionString);
        connection.Open();

        string query = @"SELECT COUNT(log_in) FROM login_table WHERE username = '"+loginClassObj.Username+"' AND password = '"+loginClassObj.Password+"'";
        SqlCommand command = new SqlCommand(query,connection);
        command.ExecuteNonQuery();
        return ???;  
    }
Run Code Online (Sandbox Code Playgroud)

c# asp.net

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

TPL与多线程

我是线程新手,我需要澄清以下情况.

我正在研究苹果推送通知服务.我的应用程序要求在向网站添加新交易时向30k用户发送通知.

我可以将30k用户分成列表,每个列表包含1000个用户并启动多个线程或可以使用任务吗?

以下方式有效吗?

if (lstDevice.Count > 0)
{

    for (int i = 0; i < lstDevice.Count; i += 2)
    {
        splitList.Add(lstDevice.Skip(i).Take(2).ToList<DeviceHelper>());
    }

    var tasks = new Task[splitList.Count];
    int count=0;
    foreach (List<DeviceHelper> lst in splitList)
    {
        tasks[count] = Task.Factory.StartNew(() =>
        {
            QueueNotifications(lst, pMessage, pSubject, pNotificationType, push);
        },
            TaskCreationOptions.None);
       count++;
    }
Run Code Online (Sandbox Code Playgroud)

QueueNotification方法将遍历每个列表项并创建一个有效负载

foreach (DeviceHelper device in splitList)
{
    if (device.PlatformType.ToLower() == "ios")
    {
        push.QueueNotification(new AppleNotification()
                                    .ForDeviceToken(device.DeviceToken)
                                    .WithAlert(pMessage)
                                    .WithBadge(device.Badge)
                                     );
        Console.Write("Waiting for Queue to Finish...");
    }
}
push.StopAllServices(true);
Run Code Online (Sandbox Code Playgroud)

c# multithreading task-parallel-library

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

使用 Corel SDK 创建 Wordperfect 文件

我们正在尝试使用 Corel sdk(WPOX7 SDK)和 .net(C#)框架创建一个完美的文件。

我正在谷歌搜索文件,但无法获得任何文件。

有谁知道,请提供样品给我。

.net c# wordperfect

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

表达式解析 - 可以将属性名称数组作为字符串?

有可能完成这个方法吗?是否可以在最新版本的C#中使用?将此视为DSL,以配置系统以查看某些对象上的某些属性更改.

List<string> list = GetProps<AccountOwner>(x => new object[] {x.AccountOwnerName, x.AccountOwnerNumber}); 
// would return "AccountOwnerName" and "AccountOwnerNumber"

public List<string> GetProps<T>(Expression<Func<T, object[]>> exp)
{  
    // code here
}
Run Code Online (Sandbox Code Playgroud)

.net c# dsl expression expression-trees

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

WPF MVVM等待:取消任务不会停止我的进度条

我正在开发一个 .NET 4.5 小型 WPF/MVVM 项目,并且我正在尝试让进度条与 async/await 一起正确工作。

我已经一切正常,但无法正确取消任务。或者,我认为任务可能被取消,但进度条无论如何都会运行完整长度。

我在“开始”和“停止”上调用“LongRun”方法,但当我想停止时使用可选的取消令牌参数。这可能是一种不寻常的做事方式,但我认为它看起来不错 - 至少在理论上:-)

这是一些代码:

视图模型

public MainViewModel()
    {
        _progress = new Progress<int>(ReportProgress);
        CountFilesCreatedCommand = new RelayCommand<IProgress<int>>(progress => LongRun(Progress));
        _tokenSource = new CancellationTokenSource();
        _tokenSource.Cancel();
        StopCountFilesCommand = new RelayCommand<CancellationToken>(token => LongRun(Progress, _tokenSource.Token));
        ProgressText = "...";
    }

    private void ReportProgress(int result)
    {
        PercentProgress = result;
    }

    private async void LongRun(IProgress<int> progress, CancellationToken token = default(CancellationToken))
    {
        try
        {
            // Start long running task here
            int i = 0;
            for (; i != 101; ++i) …
Run Code Online (Sandbox Code Playgroud)

c# wpf mvvm async-await

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

通过lambda表达式传递属性,并对其属性进行排序

我有一个ISomeType列表,其中T包含至少一个IConvertibleProperty类型的属性.例:

IConvertibleProperty
{
    string PropertyA { get; set; }
    string PropertyB { get; set; }
    // etc
}

public class SomeTypeA : ISomeType
{
    public ConvertibleProperty PropertyX { get; set; }
    // etc
}
Run Code Online (Sandbox Code Playgroud)

我需要创建一个泛型函数,我可以通过以下方式调用它:

CustomMethod(list, x => x.PropertyX);
Run Code Online (Sandbox Code Playgroud)

并且将能够在其中实现下一个排序:

protected void CustomMethod<T, TKey>(IList<T> list, Func<T, TKey> expr) where T : ISomeType where TKey : IConvertibleProperty
{
    // example of non-generic sorting (in this case expr = x.PropertyX)
    var sortedList = list.OrderBy(x => x.PropertyX.PropertyA).ThenBy(x => x.PropertyX.PropertyB).ToList();

    // rest of the …
Run Code Online (Sandbox Code Playgroud)

c# generics

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