小编Mic*_*mon的帖子

打印文件名

我是新手python,刚刚安装Eric6 我想要搜索一个文件夹(和所有子目录)来打印任何扩展名为.pdf I 的文件的文件名作为我的语法,但它错误说

调试程序引发异常未处理的FileNotFoundError
"[WinError 3]系统找不到指定的路径'C:'"
文件:C:\ Users\pcuser\EricDocs\Test.py,Line:6

这是我想要执行的语法:

import os

results = []
testdir = "C:\Test"
for folder in testdir:
  for f in os.listdir(folder):
    if f.endswith('.pdf'):
        results.append(f)

print (results)
Run Code Online (Sandbox Code Playgroud)

python python-3.x

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

Page_Load() 可以异步吗

一个能Page_Load()方法是async?我问,好像我已经这样声明了

protected void Page_Load()
Run Code Online (Sandbox Code Playgroud)

一切都按其应有的方式加载。如果我有这样的声明

protected async void Page_Load()
Run Code Online (Sandbox Code Playgroud)

Page_Load()断点不会打,也没有对catch()块被击中。

现在我试图设置我的Page_Load()方法async,以便在页面完全呈现之前执行 3 个不同的存储过程。如果我没有我的Page_Load()方法,因为async我收到这个编译错误:

await 运算符只能与异步方法一起使用。

我的代码是这样的。

private DataSet ds1 = new DataSet();
private DataSet ds2 = new DataSet();
private DataSet ds3 = new DataSet();

protected async void Page_Load(object sender, EventArgs e)
{
 if (!IsPostBack)
 {
    var task1 = GetStoreInfo();
    var task2 = GetSalespersonInfo();
    var task3 = GetManagerInfo();
    await System.Threading.Tasks.Task.WhenAll(task1, task2, task3);
    PopulateAll();
 }
Run Code Online (Sandbox Code Playgroud)

} …

c# asp.net asynchronous webforms

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

使用Async时超时

如果我只运行其中一个异步事件,则所有内容都应该完全按照应有的顺序执行.但是,当我添加所有3个事件时,我(从我收集的内容)得到了语法的超时.这是一个完整的堆栈跟踪,希望有所帮助.


System.Web.HttpUnhandledException(0X80004005):类型System.Web.HttpUnhandledException'引发的异常.---> System.NullReferenceException:对象未设置为一个对象的一个实例..
在System.Web.UI.Page.d__554.MoveNext()
在System.Web.UI.Page.HandleError(例外五)
在系统.Web.UI.Page.d__554.MoveNext()
---在抛出异常的前一个位置的堆栈跟踪结束---
在System.Runtime.CompilerServices上的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务). 位于c:\ Windows\Microsoft的ASP.pages_AsyncTest1_aspx.EndProcessRequest(IAsyncResult ar)的 System.Web.UI.Page.AsyncPageEndProcessRequest(IAsyncResult结果)的
System.Web.TaskAsyncHelper.EndTask(IAsyncResult ar)
中的TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)
.NET\Framework\v4.0.30319\Temporary ASP.NET Files\vs\14a1541c\96dbdee3\App_Web_AsyncTest1.aspx.f9b0821e.cqtg2bnc.0.cs:
System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication中的第0行. IExecutionStep.Execute()
在System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔逻辑completedSynch ronously)
异常类型:System.Web.HttpUnhandledException
消息:类型的异常"System.Web.HttpUnhandledException"被抛出.
堆栈跟踪:
在System.Web.UI.Page.HandleError(例外五)
在System.Web.UI.Page.d__554.MoveNext()
---从先前的位置在那里引发异常---堆栈跟踪结束
时系统. System.Web.UI.Page.AsyncPageEndProcessRequest(IAsyncResult结果
)
中System.Web.TaskAsyncHelper.EndTask(IAsyncResult ar)
上System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)的Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务))
在c:\ Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\vs\14a1541c\96dbdee3\App_Web_AsyncTest1.aspx.f9b0821e.cqtg2bnc.0.cs中的ASP.pages_AsyncTest1_aspx.EndProcessRequest(IAsyncResult ar)中: System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean&completedSynchronously)
上System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()的第0行

这是我想要执行的C#语法:

namespace CEDS
{
  public partial class BBLL : System.Web.UI.UserControl
  {
      private DataSet DS = new DataSet();
      private DataSet DS1 = new DataSet();
      private DataSet DS2 = new DataSet();

      protected void Page_Load(object sender, EventArgs e)
      {
        if (!IsPostBack) …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asynchronous webforms

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

使用Parallel.ForEach执行多个帖子

这是我的语法,但我的编译错误仍然存​​在 Parallel.ForEach()

System.Data.DataRow是一个类型,但像变量一样使用

我确信这是一件简单的事,我只是在俯视.下面是我的完整语法,如果有人可以帮助我找到我错过的内容,我将非常感激!

private void TryParallel()
{
  Dictionary<string, string> dic = new Dictionary<string, string>();
  string strEndpointURL = string.Format("http://sitetosenddatato.com/post");
  SqlDataReader reader;
  string strPostData = "";
  string strMessage = "";
  DataSet grds = new DataSet();
  grds = GetSQLResults();
  if (grds.Tables[0].Rows.Count >= 1)
  {
    Parallel.ForEach(DataRow, grds.Tables[0].Rows =>
    {
        dic.Add("userID", reader.GetValue(0).ToString());
        dic.Add("name", reader.GetValue(1).ToString());
        dic.Add("address", reader.GetValue(2).ToString());
        dic.Add("city", reader.GetValue(3).ToString());
        dic.Add("state", reader.GetValue(4).ToString());
        dic.Add("zip", reader.GetValue(5).ToString());
        dic.Add("Phone", reader.GetValue(6).ToString());
    });
  }
  System.Web.Script.Serialization.JavaScriptSerializer json = new System.Web.Script.Serialization.JavaScriptSerializer();
  foreach (var d in dic) { strPostData += d.Key + "=" + Server.UrlEncode(d.Value) …
Run Code Online (Sandbox Code Playgroud)

c# asp.net parallel.foreach

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