- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我试过使用这个建议:http://msdn.microsoft.com/en-us/library/ms741870.aspx (“使用后台线程处理阻塞操作”)。
这是我的代码:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
;
}
private void Process()
{
// some code creating BitmapSource thresholdedImage
ThreadStart start = () =>
{
Dispatcher.BeginInvoke(
System.Windows.Threading.DispatcherPriority.Normal,
new Action<ImageSource>(Update),
thresholdedImage);
};
Thread nt = new Thread(start);
nt.SetApartmentState(ApartmentState.STA);
nt.Start();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
button1.IsEnabled = false;
button1.Content = "Processing...";
Action action = new Action(Process);
action.BeginInvoke(null, null);
}
private void Update(ImageSource source)
{
this.image1.Source = source; // ! this line throw exception
this.button1.IsEnabled = true; // this line works
this.button1.Content = "Process"; // this line works
}
}
在标记行中,它抛出 InvalidOperationException “由于调用线程无法访问此对象,因为另一个线程拥有它。”。但是如果我删除这一行,应用程序就可以工作。
XAML:
<!-- language: xaml -->
<Window x:Class="BlackZonesRemover.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="clr-namespace:BlackZonesRemover"
Title="MainWindow" Height="600" Width="800" Loaded="Window_Loaded">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Border Background="LightBlue">
<Image Name="image1" Stretch="Uniform" />
</Border>
<Button Content="Button" Grid.Row="1" Height="23" Name="button1" Width="75" Margin="10" Click="button1_Click" />
</Grid>
</Window>
Image.Source 属性与 Button.IsEnabled 和 Button.Content 属性有什么区别?我能做什么?
最佳答案
具体建议 thresholdImage
正在后台线程上创建。要么在 UI 线程上创建它,要么在创建后卡住它。
一般建议:不同之处在于 ImageSource
是一个 DependencyObject
,因此它具有线程关联性。因此,您需要在与分配给它的 Image
相同的线程(即 UI 线程)上创建 ImageSource
,或者您需要将 Freeze()
ImageSource
一旦您创建了它,就允许任何线程访问它。
关于c# - 如何使用 Dispatcher 设置 Image.Source 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6328503/
这些指针之间有区别吗?每次通话到底发生了什么。 *p++ (*p)++, *(p)++ 最佳答案 1和3是一样的。 请记住 ++ 的后缀和一元形式。和 --有一个结果和一个副作用: x++ 的结果是
这个问题已经有答案了: difference between grep Vs cat and grep (5 个回答) 已关闭 8 年前。 我看到一个例子,其中有人这样做: cat source.tx
它曾经有效。现在,当我添加一个断点时: saveSnippet: (title, imageUrl, role) => { debugger; ... chrome (
开发.Net Web应用程序时,如果生成运行时错误,则会显示一些在Exception类中找不到的“额外”调试信息。 它显示了“源错误”部分,其中显示了代码摘录,其中行号准确显示了错误的产生位置,并显示
Firefox 中的“源”和“生成的源”有什么区别? 请举例说明。 编辑: 7 月 3 日 “搜索引擎”使用哪个来源,生成的还是生成前的? 最佳答案 Source 将显示页面加载的源(由服务器提供)。
对于具有两个不同工作表的Excel文件,我有两个OLE DB源。工作表A和工作表B。工作表A单元格I6包含日期,我想组合这两个源并在工作表B中添加一列,以将该值设置为工作表A的日期值。有可能做到吗?任
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
这是我的代码: import speech_recognition as sr r = sr.Recognizer() with sr.Microphone() as source: prin
我是 mysql 新手。我正在尝试 setter 工示例数据库 我尝试了 stackoverflow 中提到的一些方法,但没有帮助 谁能告诉我如何解决这个问题 SELECT 'LOADING depa
在终端中,我启动程序如下: 1) source env.sh 2) source activate enviroment 3) program --args 除了在 Pycharm 中并调试代码之外,
IntelliJ 如何知道目录是“源”还是“测试源”?如何始终将目录标记为“测试源”? build.gradle 1 apply plugin: 'java' apply plugin: 'idea'
这个问题类似于Source script to separate environment in R, not the global environment , 但有一个关键的转折。 考虑一个源另一个脚
和有什么区别--devtool source-map & eval-source-map ? 最佳答案 webpack 文档有一个方便的图表,说明这些不同的选项可能适合哪些情况。 他们显示eval-s
这个问题已经有答案了: Issue with virtualenv - cannot activate (36 个回答) 已关闭 4 年前。 venv) C:\Users\Sunil\PycharmP
在以前版本的 Akka Streams 中,groupBy 返回一个 Source 的 Source 可以具体化为一个 Source[Seq [A]]. 在 Akka Streams 2.4 中,我看
这个问题已经有答案了: Issue with virtualenv - cannot activate (36 个回答) 已关闭 4 年前。 venv) C:\Users\Sunil\PycharmP
是否可以获取 Bash 片段的源代码,但仅在特定条件成立时才实际提供其中的函数? 所以我要问的是,我可以无条件地获取目录中的所有文件,但获取的文件包含是否向采购外壳提供功能的逻辑。 例子: .bash
我无法查看 JavaCore.class 源代码,但我可以很好地使用代码。 例如,要查看方法JavaCore.create(..) 的源代码,我ctrl - click(或按f3) 在 JavaCor
-- Sample employee database -- See changelog table for details -- Copyright (C) 2007,2008, MySQL
当我在我的 IDE 中编译项目时它工作正常但是当我在 bamboo 中编译时它给我以下错误。 我已经检查过我在任务中配置的 jdk 版本是 1.6,我还尝试从 pom 中的 maven 插件强制执行
我是一名优秀的程序员,十分优秀!