Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
单任务多线程
  • Loading branch information
yuanwj
yuanwj committed Mar 13, 2022
commit 724bf74b889517a355687c3d427cfb269dc24e90
19 changes: 12 additions & 7 deletions src/SmartCode.Generator/BuildTasks/TableBuildTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public override async Task Build(BuildContext context)
var filterTables = FilterTable(context.GetDataSource<ITableSource>().Tables, context.BuildKey,
context.Build);
context.SetCurrentAllTable(filterTables);

var nameConverter = _pluginManager.Resolve<INamingConverter>();
var templateEngine = _pluginManager.Resolve<ITemplateEngine>(context.Build.TemplateEngine.Name);
var output = _pluginManager.Resolve<IOutput>(context.Build.Output.Type);

var tasks = filterTables.Select(table =>
{
BuildContext newContext = new BuildContext();
Expand All @@ -40,20 +45,20 @@ public override async Task Build(BuildContext context)
newContext.Output = context.Output;
newContext.SetCurrentTable(table);

return BuildTable(newContext);
return Task.Factory.StartNew(BuildTable,(newContext, nameConverter, templateEngine, output), TaskCreationOptions.LongRunning);
}).ToArray();

await Task.WhenAll(tasks);
}

private async Task BuildTable(BuildContext context)
private async void BuildTable(object obj)
{
var table = context.GetCurrentTable();
var p=((BuildContext context, INamingConverter nameConverter, ITemplateEngine templateEngine, IOutput output)) obj;
var table = p.context.GetCurrentTable();
_logger.LogInformation($"BuildTable:{table.Name} Start!");
_pluginManager.Resolve<INamingConverter>().Convert(context);
context.Result = await _pluginManager.Resolve<ITemplateEngine>(context.Build.TemplateEngine.Name)
.Render(context);
await _pluginManager.Resolve<IOutput>(context.Build.Output.Type).Output(context);
p.nameConverter.Convert(p.context);
p.context.Result = await p.templateEngine.Render(p.context);
await p.output.Output(p.context);
_logger.LogInformation($"BuildTable:{table.Name} End!");
}

Expand Down