草庐IT

threads_connected

全部标签

c# - System.Threading.Tasks 中的 NullReferenceException 调用 HttpClient.GetAsync(url)

我的MVC4.0应用程序有一个奇怪的问题。我使用REST网络服务(AmazonAssociate)。我创建了一种方法,可以在任何地方使用。缩短版是这样的:privateasyncTaskGetRequest(stringurl){stringmyresponse;HttpResponseMessageresponse=null;HttpClientclient=newHttpClient();try{response=awaitclient.GetAsync(url);myresponse=response.Content.ToString();if(myresponse.Contai

c# - 并发集合在没有 Thread.Sleep 的情况下吃太多 cpu

BlockingCollection或ConcurrentQueue的正确用法是什么,这样您就可以自由地使项目出队,而不会使用线程消耗一半或更多的CPU?我正在使用2个线程运行一些测试,除非我有至少50~100毫秒的Thread.Sleep,否则它总是会占用至少50%的CPU。这是一个虚构的例子:privatevoid_DequeueItem(){objecto=null;while(socket.Connected){while(!listOfQueueItems.IsEmpty){if(listOfQueueItems.TryDequeue(outo)){//usethedata}

c# - 未经授权的访问异常 : Invalid cross-thread access in Silverlight application (XAML/C#)

C#相对较新,想尝试使用它来使用一些第三方Web服务API。这是XAML代码这是C#代码privatevoidButton_Click(objectsender,RoutedEventArgse){HttpWebRequestrequest=(HttpWebRequest)WebRequest.Create("http://api.twitter.com/1/users/show/keykoo.xml");request.Method="GET";request.BeginGetResponse(newAsyncCallback(twitterCallback),request);}p

c# - 这是错误 ORA-12154 : TNS:could not resolve the connect identifier specified?

我有这段代码:OracleConnectioncon=newOracleConnection("datasource=localhost;userid=fastecit;password=fastecit");con.Open();stringsql="SelectuserIdfromtblusers";OracleCommandcmd=newOracleCommand(sql,con);OracleDataReaderdr=cmd.ExecuteReader();while(dr.Read()){messageBox.Show(dr[0].Tostring());}两个项目中的代码相

c# - 将锁与 Threading.Timer 一起使用

我有一个Windows服务应用程序,它使用Threading.Timer和TimerCallback在特定时间间隔进行一些处理。我需要一次将此处理代码锁定到1个线程。因此,例如,启动服务并触发第一个回调,然后启动一个线程并开始处理。只要处理在下一次回调之前完成,这就可以正常工作。例如,处理时间比平时稍长,并且在另一个线程正在处理时再次触发TimerCallback,我需要让该线程等待另一个线程完成。这是我的代码示例:staticTimertimer;staticobjectlocker=newobject();publicvoidStart(){varcallback=newTimer

c# - NHibernate 异常 : Transaction not connected, 或已断开连接

在我们的开发环境中,所有ASP.NET应用程序都运行良好。但是,当我在测试机器上部署站点时,在某些页面上出现此异常:NHibernate.TransactionException:Transactionnotconnected,orwasdisconnectedatNHibernate.Transaction.AdoTransaction.CheckNotZombied()ind:\CSharp\NH\NH\nhibernate\src\NHibernate\Transaction\AdoTransaction.cs:line406atNHibernate.Transaction.Ad

c# - Thread.Sleep(timeout) 和 ManualResetEvent.Wait(timeout) 有什么区别?

Thread.Sleep(timeout)和resetEvent.Wait(timeout)都会导致执行暂停至少timeout毫秒,那么它们之间有区别吗?我知道Thread.Sleep导致线程放弃其时间片的剩余部分,因此可能导致sleep持续时间比请求的时间长得多。ManualResetEvent对象的Wait(timeout)方法是否有同样的问题?编辑:我知道ManualResetEvent的要点是从另一个线程发出信号-现在我只关心事件的Wait方法指定超时的情况,并且没有其他来电者设置事件。我想知道按时唤醒是否比Thread.Sleep更可靠 最佳答案

c# - 执行非查询 : Connection property has not been initialized.

下午,所以我已经在这个问题上研究了几个小时,但无法真正克服最后一个障碍。下面是我正在编写的这个程序的代码:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Diagnostics;usingSystem.Data;usingSystem.Data.SqlClient;usingSystem.Configuration;namespaceTest{classProgram{staticvoidMain(){EventLogalog=newEventLog();

c# - Connection.open 无限期挂起,不抛出异常

当我尝试执行以下代码时,程序无限期挂起。我不知道为什么,似乎还有其他Unresolved话题。不过,如果无法访问IP\网站,则它会按预期工作。privatevoidDoStuff(){stringconnectionString="DataSource=www.google.com;ConnectionTimeout=5";using(SqlConnectionconnection=newSqlConnection(connectionString)){connection.Open();//HangshereindefinitelyConsole.WriteLine("Test");

c# - 预定义类型 'System.Threading.Tasks.Task' 在全局别名的多个程序集中定义

我刚刚建立了一个新的asp.netmvc4项目,结合使用最新的.net框架(4.5)和VisualStudio2012。在我添加了一些类、辅助项目等之后。我突然注意到我编译项目时收到5次相同的警告。警告指出:ASPNETCOMPILER:warningCS1685:Thepredefinedtype'System.Threading.Tasks.Task'isdefinedinmultipleassembliesintheglobalalias;usingdefinitionfrom'c:\ProgramFiles(x86)\ReferenceAssemblies\Microsoft\