我正在使用Dispatcher这样从外部切换到UI线程
Application.Current.Dispatcher.Invoke(myAction);
Run Code Online (Sandbox Code Playgroud)
但我在一些论坛上看到人们建议使用Synchronization上下文而不是Dispatcher.
SynchronizationContext.Current.Post(myAction,null);
Run Code Online (Sandbox Code Playgroud)
它们之间有什么区别,为什么SynchronizationContext要使用它?
由于intsafe.h和stdint.h两者都定义了INT8_MIN。因此,VS2010 会生成一条警告:
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\stdint.h(72): warning C4005: 'INT8_MIN' : macro redefinition
1> C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\intsafe.h(144) : see previous definition of 'INT8_MIN'
Run Code Online (Sandbox Code Playgroud)
有没有办法在 VS2010 中修复该警告。
我怎么能用我这样做的7/3/2015 12:40:02 PM格式将它转换为DateTime "dd/MM/yyyy hh:mm:ss tt":
BreackEndTime = DateTime.ParseExact(configViewModel.EndPause, "dd/MM/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);
Run Code Online (Sandbox Code Playgroud)
但我总是得到
字符串未被识别为有效的DateTime.

我在ASP项目中遇到以下错误:
The connection was not closed. The connection's current state is open
Run Code Online (Sandbox Code Playgroud)
在SqlConnection对象上调用.open()函数时.
我试过这个:
if (Conn.State != ConnectionState.Closed)
{
Log.Message(xxx);
try
{
Conn.Close();
}
catch (Exception ex)
{
Log.Error(xxxx);
}
}
Conn.Open();
Run Code Online (Sandbox Code Playgroud)
但这仍然会引发错误.Conn对象声明为:
private static readonly SqlConnection Conn = new SqlConnection(xxxx);
Run Code Online (Sandbox Code Playgroud)
知道我应该在哪里寻找解决方案
在XAML中,可以很容易地定义带有图像的按钮:
<Button x:Name="btnSound"
Click="SoundButton"
Height="40"
HorizontalAlignment="Left"
VerticalAlignment="Bottom" Margin="20,0">
<Image x:Name="speakerImg" Source="/png/btn_speak_i.png" />
</Button>
Run Code Online (Sandbox Code Playgroud)
我想这样做c#:
// Prepare two BitmapImages
BitmapImage SoundDisable = new BitmapImage(new Uri("ms-appx:///png/btn_speak_i.png",
UriKind.RelativeOrAbsolute));
BitmapImage SoundEnable = new BitmapImage(new Uri("ms-appx:///png/btn_speak.png",
UriKind.RelativeOrAbsolute));
// Define and Load Button
btnSound = new Button();
btnSound.HorizontalAlignment = HorizontalAlignment.Left;
btnSound.VerticalAlignment = VerticalAlignment.Bottom;
Thickness margin = new Thickness(0,00,20,0);
btnSound.Margin = margin;
btnSound.Click += new RoutedEventHandler(btnSound_Click);
btnSound.IsEnabled = false;
topBar.Children.Add(btnSound);
Run Code Online (Sandbox Code Playgroud)
我找不到将图像添加到按钮的方法.就像是
btnSound.Content = SoundDisable;
Run Code Online (Sandbox Code Playgroud)
不管用.它仅显示带有按钮内图像类型的文本.在XAML版本中,我设置了图像
speakerImg.Source = SoundDisable;
Run Code Online (Sandbox Code Playgroud)
因为图像是用一个定义的x:Name.
如何以编程方式将命名图像添加到我的按钮?
我正在尝试使用ostream_iterator和显示对象上的指针向量operator <<.因此,我覆盖了operator <<.我总是得到矢量元素地址的问题.如何使迭代器打印实际值?我需要专门化吗?
class A {
private:
double x;
long y;
public:
A(long xx, double yy) :x(xx), y(yy){};
~A();
void Display();
};
template<typename T>
std::ostream &operator <<(std::ostream &os, const std::vector<T> &v) {
using namespace std;
copy(v.begin(), v.end(), ostream_iterator<T>(os, "\n"));
return os;
}
int main()
{
std::vector<A*> aVect;
FillA(aVect);
cout << accountVect;
return 0;
}
//
output
00657990
006579D0
00657A48
Run Code Online (Sandbox Code Playgroud) 实际上我试图通过从我的手中解雇事件来关闭我的窗口ViewModel.一切都很好,很棒,但我知道我必须取消我的事件,以避免内存泄漏.因此我实现了IDisposable接口,我在Dispose方法中取消了事件.
以下是我的代码:
public partial class MainWindow : Window, IDisposable
{
private MainViewModel viewModel;
public MainWindow()
{
InitializeComponent();
DataContext = viewModel = new MainViewModel();
this.viewModel.RequestClose += CloseWindow;
}
void CloseWindow(object sender, EventArgs e)
{
this.Close();
}
public void Dispose()
{
////here we need to unsubscribe the event
this.viewModel.RequestClose -= this.CloseWindow;
}
}
Run Code Online (Sandbox Code Playgroud)
我需要知道的是:
GC将被调用,EXCUTE Dispose方法