我试图在WinForms C#应用程序中创建一个单独的线程,启动一个控制ProgressBar(marquee)的后台工作程序.问题在于,当我尝试将条形图设置为可见时,它什么都不做,我尝试过多种形式的Invoke,但它们似乎没有帮助.
progressBarCycle从单独的线程调用以下方法.
BackgroundWorker backgroundWorker = new BackgroundWorker();
public void progressBarCycle(int duration)
{
backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker_DoWork);
backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker_ProgressChanged);
backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker_RunWorkerCompleted);
backgroundWorker.WorkerReportsProgress = true;
backgroundWorker.WorkerSupportsCancellation = true;
backgroundWorker.RunWorkerAsync(duration);
}
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
worker.ReportProgress(0);
DateTime end = DateTime.Now.AddMilliseconds((int)e.Argument);
while (DateTime.Now <= end)
{
System.Threading.Thread.Sleep(1000);
}
}
private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (!this.IsHandleCreated)
this.CreateHandle();
statusStrip1.Invoke((MethodInvoker)delegate
{
progressBar1.Visible = false;
});
// if (!this.IsHandleCreated)
// …Run Code Online (Sandbox Code Playgroud) 在这里,我使用了一个 HTTP POST 请求Angular 6,它在 .net 核心 Web API 调用中命中,但我没有将响应输出返回到Angular 6控制台,并且在控制台中出现以下错误:
“从源‘ http://localhost:4200 ’访问 XMLHttpRequest 在‘ http://localhost:55654/api/login/auth ’已被 CORS 策略阻止:没有‘Access-Control-Allow-Origin’标头是出现在请求的资源上。”
但我有点困惑,如果它是任何CORS启用访问问题,它不会命中 Web API 调用。但它击中了 API 调用,我没有得到响应。
Angular 6 HTTP POST 要求:
this.http.post("http://localhost:55654/api/login/auth", credentials, {
headers: new HttpHeaders({
"Content-Type": "application/json"
})
}).subscribe(response => {
let token = (<any>response);
localStorage.setItem("jwt", token);
}, err => {
});
Run Code Online (Sandbox Code Playgroud)
我CORS在以下方法中启用了.NetCore Web API
Configure方法Startup.cs:
...
app.UseCors(options =>
options.WithOrigins("http://localhost:4200")
.AllowAnyMethod()
.AllowAnyHeader());
...
Run Code Online (Sandbox Code Playgroud)
ConfigureServices方法Startup.cs …
在初始化应用程序主机之前,我需要从应用程序的配置中读取一些设置以进行其他设置。
在ASP.NET Core 2.x中,在初始化应用程序主机之前读取设置,我曾用来执行以下操作:
public static void Main(string[] args)
{
//...
var configuration = new ConfigurationBuilder()
.AddEnvironmentVariables()
.AddCommandLine(args)
.AddJsonFile("appsettings.json")
.Build();
//Do something useful with the configuration...
var host = WebHost.CreateDefaultBuilder()
.UseStartup<Startup>()
.UseConfiguration(configuration)
.Build();
//...
}
Run Code Online (Sandbox Code Playgroud)
在ASP中,WebHost 不建议使用 .NET Core 3.x ,而应使用.NET Generic Host。
.NET通用主机只有一个.ConfigureHostConfiguration(),.ConfigureAppConfiguration()并且不将内置配置作为参数,而是仅接受用于设置配置的委托。
对于HTTP工作负载,您仍然可以使用该方法.UseConfiguration()公开的方法,IWebHostBuilder并且基本上与以前相同:
public static void Main(string[] args)
{
//...
var configuration = new ConfigurationBuilder()
.AddEnvironmentVariables()
.AddCommandLine(args)
.AddJsonFile("appsettings.json")
.Build();
//Do something useful with the configuration...
var host = …Run Code Online (Sandbox Code Playgroud) 我有一个奇怪的错误,我无法找出原因.根据:来自路由的id,我正在获取表privateLessons,然后搜索具有正确id的一个对象并显示到我的模板中.最后,我得到了我想要的效果,数据显示正确,但我在控制台中得到两个相同的错误:
ERROR TypeError: Cannot read property 'id' of undefined
at Object.eval [as updateRenderer] (DetailedAnnouncementComponent.html:3)
at Object.debugUpdateRenderer [as updateRenderer] (core.es5.js:13094)
at checkAndUpdateView (core.es5.js:12241)
at callViewAction (core.es5.js:12601)
at execComponentViewsAction (core.es5.js:12533)
at checkAndUpdateView (core.es5.js:12242)
at callViewAction (core.es5.js:12601)
at execEmbeddedViewsAction (core.es5.js:12559)
at checkAndUpdateView (core.es5.js:12237)
at callViewAction (core.es5.js:12601)
Run Code Online (Sandbox Code Playgroud)
如何解决?
详细-announcement.html
<div class="detailed-announcement">
{{ privateLesson.id }}
{{ privateLesson.subject }}
{{ privateLesson.category }}
{{ privateLesson.price }}
{{ privateLesson.level }}
{{ privateLesson.voivodeship }}
{{ privateLesson.city }}
{{ privateLesson.place }}
{{ privateLesson.description }}
{{ privateLesson.author }}
</div>
Run Code Online (Sandbox Code Playgroud)
详细-announcement.tmp
import …Run Code Online (Sandbox Code Playgroud) 我根据给定的变量呈现不同的文本,我只想
在 h2 标签内的特定变量处呈现。
我尝试使用正则表达式 \r 和 \n (以及组合)进行渲染,但没有用。
render() {
let {tracker} = this.props, headline;
switch(tracker){
case 1:
headline = 'That is amazing!'
break;
case 2:
headline = 'Too bad.<br />Try again'
break;
}
return(
<h2>{headline}</h2>
)
}
Run Code Online (Sandbox Code Playgroud)