我是WPF的初学者,在我的应用程序中,我需要执行一系列初始化步骤,这些步骤需要7-8秒才能完成,在此期间我的UI变得无法响应.为了解决这个问题,我在一个单独的线程中执行初始化:
public void Initialization()
{
Thread initThread = new Thread(new ThreadStart(InitializationThread));
initThread.Start();
}
public void InitializationThread()
{
outputMessage("Initializing...");
//DO INITIALIZATION
outputMessage("Initialization Complete");
}
Run Code Online (Sandbox Code Playgroud)
我已经阅读了一些文章BackgroundWorker
,关于它应该如何允许我保持我的应用程序响应,而不必编写一个线程来执行冗长的任务,但我没有成功地尝试实现它,任何人都可以告诉我怎么做这个使用BackgroundWorker
?
谢谢,Eamonn
我需要将图像文件放入我的WPF应用程序中.当我放下文件时,我目前有一个事件触发,但我不知道接下来该怎么做.我如何获得图像?为sender
对象的图像或控制?
private void ImagePanel_Drop(object sender, DragEventArgs e)
{
//what next, dont know how to get the image object, can I get the file path here?
}
Run Code Online (Sandbox Code Playgroud) 在我的SaveFileDialog中,我在过滤器中有多种类型,但是当查看对话框时,如果我选择过滤器来查看目录中该类型的文件,我只能看到第一个和最后一个过滤器的文件.
bool save;
SaveFileDialog dlg = new SaveFileDialog();
dlg.FileName = "*";
dlg.DefaultExt = "bmp";
dlg.ValidateNames = true;
dlg.Filter = "Bitmap Image (.bmp)|*.bmp|Gif Image (.gif)|*.gif |JPEG Image (.jpeg)|*.jpeg |Png Image (.png)|*.png |Tiff Image (.tiff)|*.tiff |Wmf Image (.wmf)|*.wmf";
save = (bool)dlg.ShowDialog();
if (save)
{
SaveImage(dlg.FileName);
}
Run Code Online (Sandbox Code Playgroud)
我可以看到.bmp和.wmf类型的文件如果我改变过滤器的顺序,我总是只能看到第一个和最后一个.
如果我在程序中同时运行两个线程并在其中一个上放置一个断点,那么当该断点被命中时,另一个线程是否会停止,或者它是否会继续执行?
(我用Java编写并使用NetBeans)
我想生成一个给定概率的随机数,但我不知道如何:
我需要1到3之间的数字
num = ceil(rand*3);
Run Code Online (Sandbox Code Playgroud)
但我需要不同的值来产生不同的生成概率,例如.
0.5 chance of 1
0.1 chance of 2
0.4 chance of 3
Run Code Online (Sandbox Code Playgroud)
我确信这很简单,但我想不出怎么做.
我有一个绑定到依赖属性的TextBox,我已经实现了一个PropertyChangedCallBack函数,当文本更改时我需要调用textbox.ScrollToEnd()但是我不能因为PropertChanged函数需要是静态的,有没有办法绕过这个?
static FrameworkPropertyMetadata propertyMetaData = new FrameworkPropertyMetadata("MyWindow",
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
new PropertyChangedCallback(TextProperty_PropertyChanged));
public static readonly DependencyProperty TextProperty = DependencyProperty.Register("TextProperty", typeof(string), typeof(OutputPanel),
propertyMetaData);
private void TextProperty_PropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
textbox.ScrollToEnd(); //An object reference is required for the non-static field.
}
public string Text
{
get
{
return this.GetValue(TextProperty) as string;
}
set
{
this.SetValue(TextProperty, value);
//textbox.ScrollToEnd(); // I originally called it here but I think it should be in the property changed function.
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢,
埃蒙·
我已经使用VS2010几个星期但是在过去的几天它已经完全无法使用,当我在编辑器中输入任何内容时Visual Studio抛出一个异常,然后我得到了很多intellisence错误(代码很好,我可以编译如果我在尝试使用编辑器之前运行它 - 这是日志消息:
<entry>
<record>241</record>
<time>2011/01/25 08:30:34.109</time>
<type>Error</type>
<source>Editor or Editor Extension</source>
<description>System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.VisualStudio.TextManager.Interop.IVsTextReplaceEvents'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{CF9928D9-65AE-4319-A446-94ED5C45ECDE}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
 at System.StubHelpers.StubHelpers.GetCOMIPFromRCW(Object objSrc, IntPtr pCPCMD, Boolean& pfNeedsRelease)
 at Microsoft.VisualStudio.TextManager.Interop.IVsTextReplaceEvents.OnReplace(ChangeInput[] pCI)
 at Microsoft.VisualStudio.Editor.Implementation.VsTextBufferAdapter.OnTextBufferChangedHighPriority(Object sender, TextContentChangedEventArgs e)
 at Microsoft.VisualStudio.Text.Utilities.GuardedOperations.RaiseEvent[TArgs](Object sender, EventHandler`1 eventHandlers, TArgs args)</description> …
Run Code Online (Sandbox Code Playgroud) 我有一个char**,基本上是一个字符串数组,我需要删除.这样做的正确方法是什么,以确保所有指针都被清除?
一旦我的MainWindow在坚持MVVM模式的同时加载,我试图显示一个登录窗口.所以我试图将我的主要Windows Loaded事件绑定到我的viewmodel中的事件.这是我尝试过的:
MainWindowView.xaml
<Window x:Class="ScrumManagementClient.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
DataContext="ViewModel.MainWindowViewModel"
Loaded="{Binding ShowLogInWindow}">
<Grid>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
MainWindowViewModel.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ScrumManagementClient.ViewModel
{
class MainWindowViewModel : ViewModelBase
{
public void ShowLogInWindow(object sender, EventArgs e)
{
int i = 0;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我收到的错误消息是"Loaded ="{Binding ShowLogInWindow}"无效."{Binding ShowLogInWindow}'不是有效的事件处理程序方法名称.只有生成的或代码隐藏类的实例方法才有效."
我正在Windows机器上使用sqlpackage构建数据库dacpac。该项目包含对master.dacpac
我将dacpac移至Linux计算机(docker mssql-server-linux
映像)并还原数据库。
deploy-database.sh
# publish dacpac using sqlpackage
./sqlpackage/sqlpackage /Action:Publish /sf:"/MyDb.dacpac" /tu:sa /tp:Password1 /tdn:MyDb /tsn:localhost
Run Code Online (Sandbox Code Playgroud)
错误:
没有提供文件供参考master.dacpac; 部署可能会失败。创建包时,原始引用文件位于C:$(Windows机器路径)\ MASTER.DACPAC。初始化部署(失败)在部署计划生成期间发生错误。部署无法继续。错误SQL0:无法解析对名为“ master.dacpac”的源中的外部元素的引用,因为未加载此类源。警告SQL72025:没有文件提供给参考master.dacpac。部署可能会失败。创建包时,原始引用文件位于C:$(Windows机器路径)\ MASTER.DACPAC。
添加引用时发生错误。部署无法继续。命令'/ bin / sh -c sh /deploy-database.sh'返回了非零代码:1
我尝试master.dacpac
直接添加到项目中,也将其复制到docker映像,但是发生相同的错误。
如何在引用了master.dacpac的Linux环境中还原dapac?
c# ×5
wpf ×4
.net ×2
breakpoints ×1
c++ ×1
concurrency ×1
crash ×1
dacpac ×1
data-binding ×1
docker ×1
editor ×1
image ×1
intellisense ×1
java ×1
loaded ×1
math ×1
matlab ×1
mvvm ×1
netbeans ×1
pointers ×1
probability ×1
random ×1
sql-server ×1
sqlpackage ×1
static ×1