[英]How do you set/get/use the name of a block in TPL Dataflow?
MSDN文檔顯示DataflowBlockOptions
類上有一個NameFormat
屬性,描述如下:
獲取或設置在查詢塊名稱時使用的格式字符串。
那么......你怎么設置這個名字? 這個名字怎么樣? 什么時候使用?
或者......正如我懷疑的那樣......這只是一個實際上沒有實現的設計殘余?
你沒有設置名稱,你設置一個最終會產生名稱的NameFormat
(你當然可以忽略參數並設置你想要的任何名稱,如NameFormat = "bar"
)。 您可以使用ToString
獲取名稱,例如:
var block = new ActionBlock<int>(_ => { }, new ExecutionDataflowBlockOptions
{
NameFormat = "The name format may contain up to two format items. {0} will be substituted with the block's name. {1} will be substituted with the block's Id, as is returned from the block's Completion.Id property."
});
Console.WriteLine(block.ToString());
輸出:
名稱格式最多可包含兩個格式項。 ActionBlock`1將替換為塊的名稱。 1將替換為塊的Id,從塊的Completion.Id屬性返回。
如果我們查看.Net Core上的源代碼, ToString
實現基本上是 :
return string.Format(options.NameFormat, block.GetType().Name, block.Completion.Id);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.