未声明绑定变量“D”(Bind variable “D” not declared)
我想在sqlplus中运行一个sql文件。 这个sql文件只是简单地将一个包和一些存储过程添加到数据库中。 它使用规范/主体分离惯例编写。 但是,看来包装声明部分是有问题的,导致身体部分失败。 事实上,我不确定“绑定变量”部分是否与此相关。 任何帮助将不胜感激,谢谢。
SQL*Plus: Release 11.2.0.3.0 Production on Wed Dec 20 11:41:36 2017 Copyright (c) 1982, 2011, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options SQL> set timing on; SQL> set exitcommit off; SQL> SQL> REM Output Log SQL> REM All script output is SPOOLed here. SQL> REM Recommend not to change or use SPOOL in other locations SQL> REM If you do break the spool chain, then consider using SPOOL APPEND to reestablish SQL> SQL> PROMPT ------------------------------------------------------------; ------------------------------------------------------------ SQL> PROMPT PROCESSING: D:\ucd-agent\var\work\devops.urbancode.db.ServerRegistry-OracleScripts\1.0.0.31-a23aaeb-workdir\IT\Create_table.sql; PROCESSING: D:\ucd-agent\var\work\devops.urbancode.db.ServerRegistry-OracleScripts\1.0.0.31-a23aaeb-workdir\IT\Create_table.sql SQL> PROMPT ------------------------------------------------------------; ------------------------------------------------------------ SQL> PROMPT COMMAND: @"D:\ucd-agent\var\work\devops.urbancode.db.ServerRegistry-OracleScripts\1.0.0.31-a23aaeb-workdir\IT\Create_table.sql" ; COMMAND: @"D:\ucd-agent\var\work\devops.urbancode.db.ServerRegistry-OracleScripts\1.0.0.31-a23aaeb-workdir\IT\Create_table.sql" SQL> TIMING START; SQL> @"D:\ucd-agent\var\work\devops.urbancode.db.ServerRegistry-OracleScripts\1.0.0.31-a23aaeb-workdir\IT\Create_table.sql" ; SQL> DECLARE 2 L_CNT PLS_INTEGER; 3 lv_stmt varchar2(32767); 4 BEGIN 5 --Check if the table already exists 6 SELECT COUNT(0) 7 INTO L_CNT 8 FROM ALL_TABLES T 9 WHERE T.TABLE_NAME = 'DEVOPS_UC_SERVER_REG_TABLE' 10 AND T.OWNER = 'IT'; 11 IF L_CNT > 0 THEN 12 dbms_output.put_line('The table already exists'); 13 RETURN; 14 END IF; 15 16 --Check if the constraint already exists 17 SELECT COUNT(0) 18 INTO L_CNT 19 FROM ALL_CONSTRAINTS C 20 WHERE C.CONSTRAINT_NAME = 'DEVOPS_UC_Server_Reg_PKEY' 21 AND C.OWNER = 'IT'; 22 IF L_CNT > 0 THEN 23 dbms_output.put_line('The primary key constraint already exists'); 24 RETURN; 25 END IF; 26 27 dbms_output.put_line('Creating table...'); 28 29 30 /* 31 this code is auto-generated from DBMS_METADATA. It was accessed using the following query: 32 33 SELECT 34 DBMS_METADATA.GET_DDL( 'TABLE','DEVOPS_UC_SERVER_REG_TABLE','IT') 35 FROM DUAL; 36 37 so long as the tables do not exist, and the PRIMARY KEY NAME does not already exist 38 then this will create the table with the primary key constraint. 39 otherwise, you will run into ORA-0095: name already used by existing object (if table exists) 40 or ORA-02264: name already used by an existing constraint 41 TODO: make the table name and primary key constraint name variables for ease of use/robustness 42 */ 43 lv_stmt:=q'[ 44 CREATE TABLE "IT"."DEVOPS_UC_SERVER_REG_TABLE" 45 ( "AGENTNAME" VARCHAR2(100 CHAR) NOT NULL ENABLE, 46 "SERVERNAME" VARCHAR2(100 CHAR) NOT NULL ENABLE, 47 "DATELASTDEPLOYED" TIMESTAMP (6) WITH TIME ZONE, 48 "TECHNOLOGY" VARCHAR2(100 CHAR) NOT NULL ENABLE, 49 "ISSETUP" VARCHAR2(10 CHAR), 50 CONSTRAINT "DEVOPS_UC_Server_Reg_PKEY" PRIMARY KEY ("AGENTNAME", "SERVERNAME", "TECHNOLOGY") 51 USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 52 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 53 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 54 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) 55 TABLESPACE "IT" ENABLE 56 ) SEGMENT CREATION IMMEDIATE 57 PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 58 NOCOMPRESS LOGGING 59 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 60 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 61 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) 62 TABLESPACE "IT" ]'; 63 64 execute immediate lv_stmt; 65 dbms_output.put_line('Table created successfully'); 66 67 END; 68 COMMIT; 69 PROMPT ; 70 PROMPT STATUS: SUCCESS; 71 TIMING STOP; 72 PROMPT ; 73 PROMPT ------------------------------------------------------------; 74 PROMPT PROCESSING: D:\ucd-agent\var\work\devops.urbancode.db.ServerRegistry-OracleScripts\1.0.0.31-a23aaeb-workdir\IT\UC_Server_Reg.pck.sql; 75 PROMPT ------------------------------------------------------------;
我认为这个问题可能源于以下这些方面:
76 PROMPT COMMAND: @"D:\ucd-agent\var\work\devops.urbancode.db.ServerRegistry-OracleScripts\1.0.0.31-a23aaeb-workdir\IT\UC_Server_Reg.pck.sql" ; 77 TIMING START; 78 @"D:\ucd-agent\var\work\devops.urbancode.db.ServerRegistry-OracleScripts\1.0.0.31-a23aaeb-workdir\IT\UC_Server_Reg.pck.sql" ; 78 create or replace package it.DEVOPS_UC_SERVER_REGISTRY is 79 80 81 PROCEDURE RetrieveUCServerRegTable 82 ( 83 RC1 IN OUT SYS_REFCURSOR 84 ); 85 86 PROCEDURE ExtraStoredProc 87 ( 88 RC2 IN OUT SYS_REFCURSOR 89 ); 90 91 PROCEDURE ExtraStoredProc2 92 ( 93 RC2 IN OUT SYS_REFCURSOR 94 ); 95 96 PROCEDURE InsertUCServerRegistryEntry 97 ( 98 inAgentName IN VARCHAR, 99 inIsSetup IN VARCHAR, 100 inServerName IN VARCHAR, 101 inTechnology IN VARCHAR 102 ); 103 104 end; 105 / SP2-0552: Bind variable "D" not declared. Elapsed: 00:00:00.00 SQL> SQL> show errors No errors. SQL> SQL> CREATE OR REPLACE PACKAGE BODY IT.DEVOPS_UC_SERVER_REGISTRY AS 2 3 PROCEDURE RetrieveUCServerRegTable 4 ( 5 RC1 IN OUT SYS_REFCURSOR 6 7 ) 8 IS 9 BEGIN 10 OPEN RC1 FOR 11 SELECT * 12 FROM it.DEVOPS_UC_SERVER_REG_TABLE ; 13 END RetrieveUCServerRegTable; 14 15 PROCEDURE ExtraStoredProc 16 ( 17 RC2 IN OUT SYS_REFCURSOR 18 19 ) 20 IS 21 BEGIN 22 OPEN RC2 FOR 23 SELECT * 24 FROM it.DEVOPS_UC_SERVER_REG_TABLE 25 WHERE agentName='appsrvdev11.otpp.com'; 26 END ExtraStoredProc; 27 28 PROCEDURE ExtraStoredProc2 29 ( 30 RC2 IN OUT SYS_REFCURSOR 31 32 ) 33 IS 34 BEGIN 35 OPEN RC2 FOR 36 SELECT * 37 FROM it.DEVOPS_UC_SERVER_REG_TABLE 38 WHERE agentName='ucdagentdev01.otpp.com'; 39 END ExtraStoredProc2; 40 41 42 PROCEDURE InsertUCServerRegistryEntry 43 ( 44 inAgentName IN VARCHAR, 45 inIsSetup IN VARCHAR, 46 inServerName IN VARCHAR, 47 inTechnology IN VARCHAR 48 )IS 49 50 BEGIN 51 52 MERGE INTO IT.DEVOPS_UC_SERVER_REG_TABLE 53 USING DUAL ON (IT.DEVOPS_UC_SERVER_REG_TABLE.agentName = inAgentName AND serverName = inServerName AND 54 technology = inTechnology) 55 WHEN MATCHED THEN 56 UPDATE SET DATELASTDEPLOYED = SYSDATE, 57 isSetup = inIsSetup 58 WHEN NOT MATCHED THEN 59 INSERT( agentName, isSetup, serverName , TechnoLOGY, DATELASTDEPLOYED) 60 VALUES( inAgentName, inIsSetup, inServerName, inTechnology, SYSDATE ); 61 62 63 END InsertUCServerRegistryEntry; 64 END ; 65 / Warning: Package Body created with compilation errors. Elapsed: 00:00:00.45 SQL> show errors Errors for PACKAGE BODY IT.DEVOPS_UC_SERVER_REGISTRY: LINE/COL ERROR -------- ----------------------------------------------------------------- 0/0 PL/SQL: Compilation unit analysis terminated 1/17 PLS-00201: identifier 'DEVOPS_UC_SERVER_REGISTRY' must be declared 1/17 PLS-00304: cannot compile body of 'DEVOPS_UC_SERVER_REGISTRY' without its specification SQL> COMMIT; Commit complete.
I am trying to run a sql file in sqlplus. This sql file simply adds a package and some stored procedures to the database. It is written using the specification/body separation convention. However, it appears that the package declaration part is problematic, leading to the body part failing. In fact, I am not sure if the "Binding variable" part is even relevant. Any help would be appreciated, thanks.
SQL*Plus: Release 11.2.0.3.0 Production on Wed Dec 20 11:41:36 2017 Copyright (c) 1982, 2011, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options SQL> set timing on; SQL> set exitcommit off; SQL> SQL> REM Output Log SQL> REM All script output is SPOOLed here. SQL> REM Recommend not to change or use SPOOL in other locations SQL> REM If you do break the spool chain, then consider using SPOOL APPEND to reestablish SQL> SQL> PROMPT ------------------------------------------------------------; ------------------------------------------------------------ SQL> PROMPT PROCESSING: D:\ucd-agent\var\work\devops.urbancode.db.ServerRegistry-OracleScripts\1.0.0.31-a23aaeb-workdir\IT\Create_table.sql; PROCESSING: D:\ucd-agent\var\work\devops.urbancode.db.ServerRegistry-OracleScripts\1.0.0.31-a23aaeb-workdir\IT\Create_table.sql SQL> PROMPT ------------------------------------------------------------; ------------------------------------------------------------ SQL> PROMPT COMMAND: @"D:\ucd-agent\var\work\devops.urbancode.db.ServerRegistry-OracleScripts\1.0.0.31-a23aaeb-workdir\IT\Create_table.sql" ; COMMAND: @"D:\ucd-agent\var\work\devops.urbancode.db.ServerRegistry-OracleScripts\1.0.0.31-a23aaeb-workdir\IT\Create_table.sql" SQL> TIMING START; SQL> @"D:\ucd-agent\var\work\devops.urbancode.db.ServerRegistry-OracleScripts\1.0.0.31-a23aaeb-workdir\IT\Create_table.sql" ; SQL> DECLARE 2 L_CNT PLS_INTEGER; 3 lv_stmt varchar2(32767); 4 BEGIN 5 --Check if the table already exists 6 SELECT COUNT(0) 7 INTO L_CNT 8 FROM ALL_TABLES T 9 WHERE T.TABLE_NAME = 'DEVOPS_UC_SERVER_REG_TABLE' 10 AND T.OWNER = 'IT'; 11 IF L_CNT > 0 THEN 12 dbms_output.put_line('The table already exists'); 13 RETURN; 14 END IF; 15 16 --Check if the constraint already exists 17 SELECT COUNT(0) 18 INTO L_CNT 19 FROM ALL_CONSTRAINTS C 20 WHERE C.CONSTRAINT_NAME = 'DEVOPS_UC_Server_Reg_PKEY' 21 AND C.OWNER = 'IT'; 22 IF L_CNT > 0 THEN 23 dbms_output.put_line('The primary key constraint already exists'); 24 RETURN; 25 END IF; 26 27 dbms_output.put_line('Creating table...'); 28 29 30 /* 31 this code is auto-generated from DBMS_METADATA. It was accessed using the following query: 32 33 SELECT 34 DBMS_METADATA.GET_DDL( 'TABLE','DEVOPS_UC_SERVER_REG_TABLE','IT') 35 FROM DUAL; 36 37 so long as the tables do not exist, and the PRIMARY KEY NAME does not already exist 38 then this will create the table with the primary key constraint. 39 otherwise, you will run into ORA-0095: name already used by existing object (if table exists) 40 or ORA-02264: name already used by an existing constraint 41 TODO: make the table name and primary key constraint name variables for ease of use/robustness 42 */ 43 lv_stmt:=q'[ 44 CREATE TABLE "IT"."DEVOPS_UC_SERVER_REG_TABLE" 45 ( "AGENTNAME" VARCHAR2(100 CHAR) NOT NULL ENABLE, 46 "SERVERNAME" VARCHAR2(100 CHAR) NOT NULL ENABLE, 47 "DATELASTDEPLOYED" TIMESTAMP (6) WITH TIME ZONE, 48 "TECHNOLOGY" VARCHAR2(100 CHAR) NOT NULL ENABLE, 49 "ISSETUP" VARCHAR2(10 CHAR), 50 CONSTRAINT "DEVOPS_UC_Server_Reg_PKEY" PRIMARY KEY ("AGENTNAME", "SERVERNAME", "TECHNOLOGY") 51 USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 52 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 53 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 54 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) 55 TABLESPACE "IT" ENABLE 56 ) SEGMENT CREATION IMMEDIATE 57 PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 58 NOCOMPRESS LOGGING 59 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 60 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 61 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) 62 TABLESPACE "IT" ]'; 63 64 execute immediate lv_stmt; 65 dbms_output.put_line('Table created successfully'); 66 67 END; 68 COMMIT; 69 PROMPT ; 70 PROMPT STATUS: SUCCESS; 71 TIMING STOP; 72 PROMPT ; 73 PROMPT ------------------------------------------------------------; 74 PROMPT PROCESSING: D:\ucd-agent\var\work\devops.urbancode.db.ServerRegistry-OracleScripts\1.0.0.31-a23aaeb-workdir\IT\UC_Server_Reg.pck.sql; 75 PROMPT ------------------------------------------------------------;
I believe the issue probably stems from these lines and below:
76 PROMPT COMMAND: @"D:\ucd-agent\var\work\devops.urbancode.db.ServerRegistry-OracleScripts\1.0.0.31-a23aaeb-workdir\IT\UC_Server_Reg.pck.sql" ; 77 TIMING START; 78 @"D:\ucd-agent\var\work\devops.urbancode.db.ServerRegistry-OracleScripts\1.0.0.31-a23aaeb-workdir\IT\UC_Server_Reg.pck.sql" ; 78 create or replace package it.DEVOPS_UC_SERVER_REGISTRY is 79 80 81 PROCEDURE RetrieveUCServerRegTable 82 ( 83 RC1 IN OUT SYS_REFCURSOR 84 ); 85 86 PROCEDURE ExtraStoredProc 87 ( 88 RC2 IN OUT SYS_REFCURSOR 89 ); 90 91 PROCEDURE ExtraStoredProc2 92 ( 93 RC2 IN OUT SYS_REFCURSOR 94 ); 95 96 PROCEDURE InsertUCServerRegistryEntry 97 ( 98 inAgentName IN VARCHAR, 99 inIsSetup IN VARCHAR, 100 inServerName IN VARCHAR, 101 inTechnology IN VARCHAR 102 ); 103 104 end; 105 / SP2-0552: Bind variable "D" not declared. Elapsed: 00:00:00.00 SQL> SQL> show errors No errors. SQL> SQL> CREATE OR REPLACE PACKAGE BODY IT.DEVOPS_UC_SERVER_REGISTRY AS 2 3 PROCEDURE RetrieveUCServerRegTable 4 ( 5 RC1 IN OUT SYS_REFCURSOR 6 7 ) 8 IS 9 BEGIN 10 OPEN RC1 FOR 11 SELECT * 12 FROM it.DEVOPS_UC_SERVER_REG_TABLE ; 13 END RetrieveUCServerRegTable; 14 15 PROCEDURE ExtraStoredProc 16 ( 17 RC2 IN OUT SYS_REFCURSOR 18 19 ) 20 IS 21 BEGIN 22 OPEN RC2 FOR 23 SELECT * 24 FROM it.DEVOPS_UC_SERVER_REG_TABLE 25 WHERE agentName='appsrvdev11.otpp.com'; 26 END ExtraStoredProc; 27 28 PROCEDURE ExtraStoredProc2 29 ( 30 RC2 IN OUT SYS_REFCURSOR 31 32 ) 33 IS 34 BEGIN 35 OPEN RC2 FOR 36 SELECT * 37 FROM it.DEVOPS_UC_SERVER_REG_TABLE 38 WHERE agentName='ucdagentdev01.otpp.com'; 39 END ExtraStoredProc2; 40 41 42 PROCEDURE InsertUCServerRegistryEntry 43 ( 44 inAgentName IN VARCHAR, 45 inIsSetup IN VARCHAR, 46 inServerName IN VARCHAR, 47 inTechnology IN VARCHAR 48 )IS 49 50 BEGIN 51 52 MERGE INTO IT.DEVOPS_UC_SERVER_REG_TABLE 53 USING DUAL ON (IT.DEVOPS_UC_SERVER_REG_TABLE.agentName = inAgentName AND serverName = inServerName AND 54 technology = inTechnology) 55 WHEN MATCHED THEN 56 UPDATE SET DATELASTDEPLOYED = SYSDATE, 57 isSetup = inIsSetup 58 WHEN NOT MATCHED THEN 59 INSERT( agentName, isSetup, serverName , TechnoLOGY, DATELASTDEPLOYED) 60 VALUES( inAgentName, inIsSetup, inServerName, inTechnology, SYSDATE ); 61 62 63 END InsertUCServerRegistryEntry; 64 END ; 65 / Warning: Package Body created with compilation errors. Elapsed: 00:00:00.45 SQL> show errors Errors for PACKAGE BODY IT.DEVOPS_UC_SERVER_REGISTRY: LINE/COL ERROR -------- ----------------------------------------------------------------- 0/0 PL/SQL: Compilation unit analysis terminated 1/17 PLS-00201: identifier 'DEVOPS_UC_SERVER_REGISTRY' must be declared 1/17 PLS-00304: cannot compile body of 'DEVOPS_UC_SERVER_REGISTRY' without its specification SQL> COMMIT; Commit complete.
原文:https://stackoverflow.com/questions/47910800
最满意答案
从本质上讲,它们都是异步执行的,但是以一种方式对另一种方式进行操作的专业人员是什么?
直接调用该方法将在当前线程上异步执行它。 被调用的方法将继承调用方法的上下文,并将使用当前的
SynchronizationContext
(如果为null
,则使用当前的TaskScheduler
)继续执行。 我在博客上详细解释了这一点 。通过
StartNew
调用该方法将在当前TaskScheduler
上异步执行它。 通常,这是线程池任务调度程序,除非调用代码作为委托任务 (我的博客上定义的术语)的一部分执行。 除非该任务是使用HideScheduler
选项 (在我的博客中描述) 启动的,否则即使存在执行该代码的TaskScheduler
,也没有当前的TaskScheduler
。如果
StartNew
场景听起来很复杂,那是因为它是。StartNew
仅适用于专家。 我有一篇关于为什么不应该使用StartNew
博客文章。更直观的比较是直接调用方法和通过
Task.Run
调用方法。 与StartNew
不同,Task.Run
总是在线程池线程上执行其代码,因此该方法将在线程池上异步运行。对于真实世界的代码,您应该只在需要时使用
Task.Run
。 如果方法是正确异步的(即,它不首先计算分形或任何东西),那么你不应该使用Task.Run
。 你根本不应该使用StartNew
。In essence, they both execute asynchronously, but what are the pro's/con's of doing it one way over the other?
Calling the method directly will execute it asynchronously on the current thread. The called method will inherit the context of the calling method, and will use the current
SynchronizationContext
(or, if that isnull
, the currentTaskScheduler
) to resume executing. I explain this in full on my blog.Calling the method via
StartNew
will execute it asynchronously on the currentTaskScheduler
. Generally, this is the thread pool task scheduler, unless the calling code is executing as part of a Delegate Task (a term defined on my blog). Unless that task was started with theHideScheduler
option (described on my blog), in which case there is no currentTaskScheduler
even though there is aTaskScheduler
executing that code.If the
StartNew
scenario sounds complicated, that's because it is.StartNew
is only for experts. I have an entire blog post on whyStartNew
should not be used.A more realistic comparison would be between calling the method directly and calling the method via
Task.Run
. UnlikeStartNew
,Task.Run
always executes its code on a thread pool thread, so the method will run asynchronously on the thread pool.For real-world code, you should only use
Task.Run
when you need to. If the method is properly asynchronous (i.e., it doesn't calculate a fractal first or anything), then you shouldn't useTask.Run
. And you shouldn't useStartNew
at all.
相关问答
更多-
从任务调用Func(Calling a Func From a Task)[2023-03-01]
在您的RunReport方法中,您实际上并没有调用method Func。 您正在重新调整method委托。 这就是Task.Result被推断为Func<> 。 var task = Task.Factory.StartNew(() => method, token); 以上代码等于 var task = Task.Factory.StartNew(() => { r ... -
所以我在这个问题的帮助下找出了我的问题的答案 - 使用Windows服务的凭据启动进程 看起来,一个Web服务是通过“网络服务”权限执行的,并且在检查Windows事件查看器时,我得到了访问冲突 - 这意味着我需要以具有适当权限的用户身份执行这段代码。 所以我遵循我链接的问题中提供的逻辑,以创建一个执行一个简单的exe文件的过程,我设置了一个简单的exe文件来执行我发布的代码块。 我必须小心地给我的用户适当的权限访问该文件夹与exe文件,这是非常多的。 使用这种技术,似乎很容易设置一个Web服务,它执行Ed ...
-
从本质上讲,它们都是异步执行的,但是以一种方式对另一种方式进行操作的专业人员是什么? 直接调用该方法将在当前线程上异步执行它。 被调用的方法将继承调用方法的上下文,并将使用当前的SynchronizationContext (如果为null ,则使用当前的TaskScheduler )继续执行。 我在博客上详细解释了这一点 。 通过StartNew调用该方法将在当前TaskScheduler上异步执行它。 通常,这是线程池任务调度程序,除非调用代码作为委托任务 (我的博客上定义的术语)的一部分执行。 除非该 ...
-
除非我弄错了,否则所有这三个看起来都会完全相同,尽管有一个微妙的区别。 选项1将直接执行DoAsync,而另外两个调用自己调用DoAsync的函数。 这将在您的堆栈上创建一个额外的条目。 与2相比,相同的逻辑适用于选项3,还有一个额外的await调用,因此(除非编译器将其优化掉)我会期望它生成一个额外的状态。 然而,看到这些之间存在明显的运行时间差异,我希望能够进入微优化领域。 Unless I'm mistaken, all three of these will seemingly execute id ...
-
从Task.Factory更新GUI(Update GUI From Task.Factory)[2021-10-19]
您将需要长时间运行的工作,并在单独的任务中更新UI。 原因是长期运行的g任务不应该在UI线程上,但更新必须是本质上的。 所以使用continuewith是一种非常常见的模式。 当您使用continuewith时,请确保将ui上下文作为调度程序传递。 所以,从UIthread(重要!)做task.ContinueWith传递taskscheduler.fromcurrentsynchronizationcontext作为可选的任务调度程序参数。 编辑:刚刚实现了你使用asp.net。 我假设您使用的是Web表 ... -
两者都是一样的。 如果要将方法发送到任务队列,则需要使用apply_async或装饰对象的delay方法。 Both are same. If you want to send the method to task queue, you need to use apply_async or delay methods of the decorated object.
-
为了找出速度慢得多的原因,您可以使用Console.WriteLine($"{event name} {DateTime.Now}")在visual studio中跟踪事件,然后在输出窗口中查看最多花费的时间。 但是关于替代方案,我建议您使用BackgroundWorker来运行您的任务。 请注意,您需要调用控件才能通过backgroundWorker更改ui BackgroundWorker _worker = new BackgroundWorker(); _worker.DoWork+=(o,args ...
-
多个Task.Factory的(Multiple Task.Factory's)[2021-12-08]
如果您使用.NET 4.0: LimitedConcurrencyLevelTaskScheduler (并发级别为1;请参见此处 ) 如果您使用.NET 4.5: ConcurrentExclusiveSchedulerPair (仅从该对中获取独占调度程序;请参见此处 ) 创建两个调度程序并将它们传递给相应的StartNew 。 或者使用这些调度程序创建两个TaskFactories并使用它们来创建和启动任务。 If you use .NET 4.0: LimitedConcurrencyLevelTa ... -
通过从C#调用非异步Func
,返回F#函数中的Async [2023-11-09]?(Return started Async in F# function from calling a non-async Func from C#?) BazWrapper返回Async>因为这就是StartChild所做的:它接受Async<'T>并返回Async > 。 目的是在异步计算表达式中使用它,以便您可以启动多个“子”异步。 Async.Start与Async.StartChild示例代码示例: async { //(...async stuff...) for msg in msgs do let! child = asyncSendMsg msg |> Async.S ... -
根据文档 ,有一个重载只接受函数及其参数。 您正在使用接受更具体策略的重载。 async(f, args...)相当于async(std::launch::async | std::launch::deferred, f, args...) ,其中两个标志的存在将其留给实现关于函数是否简单地从当前调用堆栈解耦(延迟执行第一个非定时等待函数;这称为惰性求值 ),或者实际上是多线程的。 通过仅提供 std::launch::async , 您正在使用的调用确保该函数在其自己的线程中明确执行,从而避免阻塞调用线程 ...