小编Joe*_*Bob的帖子

异步任务..无法调用executeOnExecutor()

我在Android应用程序中运行的一些异步任务有点问题.由于我正在使用某些网络IO,因此有时需要比预期更长的时间并阻止其他异步任务运行.

我需要保持我的目标和min sdk版本,但它们的目标是targetSdkVersion ="15",minSdkVersion ="8".我需要它,以便在调用异步任务时,我可以检查设备SDK,如果大于11,它可以调用executeOnExecutor()而不是执行以允许设备并行运行这些并阻止此阻塞操作.

虽然我的目标SDK为15,但我使用的设备的SDK为17.

但是在打电话时:

MyAsyncTask(this).executeOnExecutor();
Run Code Online (Sandbox Code Playgroud)

我收到错误"方法executeOnExecutor()未定义类型",我唯一可用的选项是:

MyAsyncTask(this).execute();
Run Code Online (Sandbox Code Playgroud)

MyAsyncTask是一个类对象,它扩展了AsyncTask并重载了标准方法onPreExecute,doInBackground,onProgressUpdate和onPostExecute.

我试着遵循这里列出的一些建议...... http://steveliles.github.io/android_s_asynctask.html

android android-asynctask

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

过滤DataTable,其中表不包含List <string>中的项

我在查询DataSet.Tables [0]时遇到一些问题,并删除了不符合List的标准的行.

//This is my list
var values = new List<string> {"Test", "Test2"};

// Now I just query the DataSet for anything that doesnt match this list
var query = from x in ds.Tables[0].AsEnumerable()
            from b in values
            where !x.Field<string>("ColumnName").Contains(b)
            select x;
Run Code Online (Sandbox Code Playgroud)

这工作并返回结果,但它返回2 x组相同的行(我假设因为没有连接).

我怎样才能获得这些行的不同值?

c# linq

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

列出<接口>执行顺序

我有一个带有方法的泛型接口,它返回一个int值,如下面的(简化)代码.对我来说重要的是应该以特定的顺序调用它们(例如,ClassA总是需要在ClassB之前调用).我将如何确保此排序始终正确无误.依靠列表创建者不是最好的方法吗?

谢谢.

public interface IMyInterface
{
    int DoWork();
}

public class MyClassA : IMyInterface
{
    private int _myAccumulator = 100;

    public int DoWork()
    {
        _myAccumulator -= 1;

        return _myAccumulator;
    }
}

public class MyClassB : IMyInterface
{
    private int _myAccumulator = 50;

    public int DoWork()
    {
        _myAccumulator -= 1;

        return _myAccumulator;
    }
}


public class MyWorker
{
    private List<IMyInterface> _myAccumulatorClasses = new List<IMyInterface> { new MyClassA(), new MyClassB() }

    public void CallClasses()
    {
        foreach(var accumulator in myAccumulatorClasses)
        {
            var value …
Run Code Online (Sandbox Code Playgroud)

.net c#

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

在Timer.Elapsed事件上更新MainWindow

我正在编写一个家庭WPF应用程序,它以一个配置的间隔从服务器获取文件.

这是一个基本的窗口,有几个标签.我有以下内容

  • 开始时间(反映DateTime点击"开始"事件
  • 持续时间(反映应用程序运行的时间)
  • 速度(文件的下载速度)

我想每秒更新主窗口上的持续时间,所以我有以下代码来执行此操作(在单独的类"RunDownloader.cs"中).

    private void StartTickTimer()
    {
        const double interval = 1000;

        if (_tickTimer == null)
        {
            _tickTimer = new Timer
            {
                Interval = interval
            };
            _tickTimer.Elapsed += _ticktimer_Elapsed;
        }

        _tickTimer.Start();
    }
Run Code Online (Sandbox Code Playgroud)

在_ticktimer_Elapsed上,我在主窗口_mainWindow.UpdateTicker()中调用一个方法;

这样做如下.

    public void UpdateTicker()
    {
        var timeStarted = lblTimeStarted.Content.ToString();
        DateTime startTime = DateTime.Parse(timeStarted);
        TimeSpan span = DateTime.Now.Subtract(startTime);

        //ToDo: Output time taken here!
        //lblTimeElapsed.Content =
    }
Run Code Online (Sandbox Code Playgroud)

我有两个问题.

  1. 调用lblTimeStarted.Content.ToString()时,我有以下异常; 在UpdateTicker()中

        "The calling thread cannot access this object because a different thread owns it."
    
    Run Code Online (Sandbox Code Playgroud)
  2. 我不太清楚,如何正确显示来自TimeSpan的lblTimeElapsed.Content的持续时间

提前感谢您的任何答案.:d

c# wpf

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

标签 统计

c# ×3

.net ×1

android ×1

android-asynctask ×1

linq ×1

wpf ×1