小编Ali*_*Ali的帖子

在C#中从线程更新进度条

    public class Consumer
    {
        Queue<int> queue;
        Object lockObject;

        public Consumer(Queue<int> queue, Object lockObject)
        {
            this.queue = queue;
            this.lockObject = lockObject;
        }

        public void consume(string filepath)
        {
            int item = 0;


            while (true)
            {
                lock (lockObject)
                {
                    if (queue.Count == 0)
                    {
                        Monitor.PulseAll(lockObject);
                        continue;
                    }

                    item = queue.Dequeue();
                    if (item == 0)
                    {
                        break;
                    }

                   //do some staff
                }

            }

        }
    }




    public class Producer 
    {
        Queue<int> queue;
        Object lockObject;

        public int ProgressPercent = 0;
        int TotalProducedElements = 0;
        public bool …
Run Code Online (Sandbox Code Playgroud)

c#

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

C#串口写字节

在C#中将单个字节写入.NET 4.0中的串行端口会导致a

用户代码未处理InvalidOperationException

每次将一个字节发送到SerialPort.

如何将单个字节写入串行端口?

    //Serial Init
    //Full fledged constuctor
    public NetCommManager(String portName, TransmissionType trans, String baud, String parity, String stopBits, String dataBits)
    {
        nc_baudRate = baud;
        nc_parity = parity;
        nc_stopBits = stopBits;
        nc_dataBits = dataBits;
        nc_portName = portName;
        nc_transType = trans;

        //now add an event handler
        comPort.DataReceived += new SerialDataReceivedEventHandler(netComm_DataReceived);
    }
Run Code Online (Sandbox Code Playgroud)

配置:

       _commManger = new NetCommManager(commPortNumber,                        
       NetCommManager.TransmissionType.Text, "19200", "None", "One", "8");
Run Code Online (Sandbox Code Playgroud)

要写的字节:

_commManager.WriteByte(Convert.ToByte( 0x7B));
Run Code Online (Sandbox Code Playgroud)

WriteByte函数为:

public void WriteByte(byte data)
        {
            //change data to array
            //byte[] dataArray = …
Run Code Online (Sandbox Code Playgroud)

c# byte serial-port send

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

获取共享打印机的打印队列详细信息

正在尝试在共享打印机上打印文档;我需要获取打印队列详细信息。以下代码始终从“Microsoft XPS 文档”获取队列,因为作业数 = 0。但我的默认打印机配置为“HP LaserJet P1505n”

LocalPrintServer server = new LocalPrintServer()
PrintQueueCollection queueCollection = server.GetPrintQueues();
PrintQueue printQueue = null;
foreach (PrintQueue pq in queueCollection)
{
 Logger.LogInfo("PrintQueue1", "Printer1 Queue Name " + pq.FullName);
 printQueue = pq;
 numberOfJobs = printQueue.NumberOfJobs;
 Logger.LogInfo("numberOfJobs1"+ numberOfJobs);
}
Run Code Online (Sandbox Code Playgroud)

如何从该特定共享打印机获取打印队列详细信息?我也试过

PrintServer server = new PrintServer(@"\\192.168.100.168\HP LaserJet P1505n");
Run Code Online (Sandbox Code Playgroud)

但得到错误为:

Win32 错误:文件名、目录名或卷标语法不正确

我在这里缺少什么?

.net c# printing system.printing printqueue

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

将属性/索引添加到数组中的每个元素

我调用一个返回一个对象数组的webservice:

$.ajax({
  dataType: "json",
  url: "WebServices/FetchMenu.aspx?P=0&L=2&mt=1",
  //data: data,
  success: function (data) {
    var foo = data;
  }
});
Run Code Online (Sandbox Code Playgroud)

这是回应:

[
    {
        color: "red",
        value: "#f00"
    },
    {
        color: "green",
        value: "#0f0"
    },
    {
        color: "blue",
        value: "#00f"
    },
    {
        color: "cyan",
        value: "#0ff"
    }
]
Run Code Online (Sandbox Code Playgroud)

我想row_number为每个元素添加一个属性,该元素包含数组中元素的当前索引.

我需要这个,因为我稍后会更改元素的顺序,但希望能够识别元素的原始位置.

javascript

3
推荐指数
2
解决办法
2590
查看次数

如何连接运行Android 4.4的Android IPTV机顶盒进行USB调试

我正在开发在Android 4.4上运行的android IPTV应用程序。有谁知道如何连接机顶盒以安装用于测试的应用程序。机顶盒具有用于连接USB笔式驱动器的USB端口。

我们可以使用该USB端口直接在STB中安装应用程序吗?如果是,那怎么办?

如果有人从事android机顶盒编程工作,请帮助我。

android google-tv android-tv

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

动态LINQ表达式

我正在尝试实现这个如何在Linq where子句中指定动态字段名称?并得到一个编译器错误,说:

无法解析方法'Where(System.Linq.Expressions.LambdaExpression

public class Employee
{
    public string Name { get; private set; }
    public int Salary { get; private set; }

    public Employee(string name, int salary)
    {
        Name = name;
        Salary = salary;
    }
}
Run Code Online (Sandbox Code Playgroud)

然后在控制台应用程序的主要方法

var employees = new List<Employee>
{
    new Employee("Bob", 45000),
    new Employee("Jane", 25000),
    new Employee("Jim", 5)
};

var eParam = Expression.Parameter(typeof(Employee), "e");

var comparison = Expression.Lambda(
    Expression.LessThan(
        Expression.Property(eParam, "Salary"),
        Expression.Constant(40000)),
    eParam);
var c = from e in employees.Where(comparison) // COMPILER ERROR …
Run Code Online (Sandbox Code Playgroud)

c# linq

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

Windows 10不支持SystemTray

使用Java 8 SDK时

if (SystemTray.isSupported()) {
   logger.error("SystemTray IS supported");
} else {
    logger.error("SystemTray IS NOT supported");
}
Run Code Online (Sandbox Code Playgroud)

为什么Windows 10不支持SystemTray?

我应该怎么做才能使其得到支持?

谢谢

java system-tray

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

如何在Apache Ignite 2.0上存储堆数据

CacheConfiguration<String, JSONObject> conf = new CacheConfiguration<String, JSONObject>();
conf.setName("ABC");
conf.setWriteThrough(true);
conf.setReadThrough(true);
conf.setMemoryMode(CacheMemoryMode.OFFHEAP_TIERED);
conf.setOffHeapMaxMemory(0);
Run Code Online (Sandbox Code Playgroud)

这是我在ignite 1.9中的缓存配置,但是当我将Apache Ignite从1.9升级到2.0时,我在最后两行配置时遇到错误.

caching gridgain in-memory-database ignite

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

在创建类的实例中,关键字"new"和"default"之间有所不同

我有这样的课:

 class foo
    {
        public foo(string Text)
        {
        }
    }
Run Code Online (Sandbox Code Playgroud)

运行此代码以创建类的实例后,obj1设置为null:

foo obj1 = default(foo);
Run Code Online (Sandbox Code Playgroud)

通过打击代码一切正常:

foo obj2= new foo("bla bla");
Run Code Online (Sandbox Code Playgroud)

我有2个问题:

  1. 运行时默认承包商会发生什么default(foo);
  2. foo obj1 = default(foo);等于foo obj1 = null

提前致谢.

c# constructor

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

获取DisplayName属性的所有值

我正在使用带有EntityFramework 6 DataAnnotations的asp.net MVC 5。我想知道是否有一种方法来获取所有DisplayName对象并将它们保存在变量中到Controller类中。

例如,考虑以下类:

public class Class1
{
    [DisplayName("The ID number")]
    public int Id { get; set; }

    [DisplayName("My Value")]
    public int Value { get; set; }

    [DisplayName("Label name to display")]
    public string Label { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

如何获取DisplayName所有属性的值?例如,如何创建一个返回a的函数,该函数Dictionary< string,string >的键具有属性名称和值为的键DisplayName,如下所示:

{ "Id": "The ID name", "Value": "My Value", "Label": "Label name to display"}.
Run Code Online (Sandbox Code Playgroud)

我已经看到了这个主题stackoverflow-获取DisplayName属性的值,但是我不知道扩展此代码的方法。

c# asp.net-mvc data-annotations entity-framework-6

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