我正在转换使用SQL Server的遗留应用程序,我想将petapoco用于我的数据访问层.
表定义包含许多具有DEFAULT值的列.
我希望我的DAL在插入新记录时处理默认值.
不幸的是,使用该ResultColumn属性不是解决方案,因为当我使用UPDATE和INSERT时会丢弃该列.DEFAULT值与读取计算的字段不完全相同.
有办法处理这个吗?
我在 aspnet 核心应用程序中使用BackgroundService对象。
关于 ExecuteAsync 方法中运行的操作的实现方式,Aspnet 核心无法正确初始化或停止。这是我尝试过的:
我按照文档ExecuteAsync中解释的方式实现了抽象方法。
管道变量是IEnumerable<IPipeline>注入到构造函数中的变量。
public interface IPipeline {
Task Start();
Task Cycle();
Task Stop();
}
...
protected override async Task ExecuteAsync(CancellationToken stoppingToken) {
log.LogInformation($"Starting subsystems");
foreach(var engine in pipeLine) {
try {
await engine.Start();
}
catch(Exception ex) {
log.LogError(ex, $"{nameof(engine)} failed to start");
}
}
log.LogInformation($"Runnning main loop");
while(!stoppingToken.IsCancellationRequested) {
foreach(var engine in pipeLine) {
try {
await engine.Cycle();
}
catch(Exception ex) {
log.LogError(ex, $"{engine.GetType().Name} error in Cycle");
}
} …Run Code Online (Sandbox Code Playgroud) 我有一个表格OpenFileDialog用于选择图像并显示它pictureBox.在表单打开之前,用户可以打开然后根据需要多次保存打开的图像.我想要做的是,在每次新的选择 - 保存之后,删除之前保存的图像(如果有的话).问题是,当我实现代码时,我能够第一次删除图像,如果我继续使用当前打开的表单保存图像,我会收到资源正在使用的错误.我所做的是Dispose()图像,但我想我不是在正确的地方做的.
这是我打开和加载图像的方式:
private void btnExplorer_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Title = "Select file";
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = fileNameFilter;
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
openFileDialog1.FileName = prefixFilter;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
pictureBox1.InitialImage = new Bitmap(openFileDialog1.FileName);
pictureBox1.ImageLocation = openFileDialog1.FileName;
selectedFile = pictureBox1.ImageLocation;
selectedFileName = openFileDialog1.SafeFileName;
pictureBox1.Load();
}
catch (Exception ex)
{
logger.Error(ex.ToString());
MessageBox.Show("Error loading image!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
Run Code Online (Sandbox Code Playgroud)
在同一个类中,我有这个方法,如果我需要删除旧图像,我会调用它:
public void …Run Code Online (Sandbox Code Playgroud) 我正在使用ConcurrentDictionary,我需要使用删除元素TryRemove.
实现TryRemove需要一个out参数来返回将被删除的对象.
Body dummy;
if (!bulletBodies.TryRemove(bullet, out dummy))
{
}
...
Run Code Online (Sandbox Code Playgroud)
每当我删除字典中的条目时,我都不想在虚拟变量上使用额外的行:这就是为什么我试图绕过out返回参数不成功地键入下面的恐怖.我也google了一下,但没有成功.
bulletBodies.TryRemove(bullet, null);
bulletBodies.TryRemove(bullet, out null);
bulletBodies.TryRemove(bullet, void);
...
Run Code Online (Sandbox Code Playgroud)
有没有办法或聪明的提示来管理未使用的输出参数,所以没有必要在任何地方声明虚拟变量?
c# ×3
.net ×1
asp.net-core ×1
default ×1
dispose ×1
null ×1
out ×1
parameters ×1
petapoco ×1
picturebox ×1
sql-server ×1
task ×1
void ×1
winforms ×1