我有异常处理和并行任务的问题.
下面显示的代码启动2个任务并等待它们完成.我的问题是,如果任务抛出异常,则永远不会到达catch处理程序.
List<Task> tasks = new List<Task>();
try
{
tasks.Add(Task.Factory.StartNew(TaskMethod1));
tasks.Add(Task.Factory.StartNew(TaskMethod2));
var arr = tasks.ToArray();
Task.WaitAll(arr);
}
catch (AggregateException e)
{
// do something
}
Run Code Online (Sandbox Code Playgroud)
但是,当我使用以下代码等待超时的任务时,会捕获异常.
while(!Task.WaitAll(arr,100));
Run Code Online (Sandbox Code Playgroud)
我似乎错过了一些东西,因为文档WaitAll描述了我的第一次尝试是正确的.请帮助我理解它为什么不起作用.
正如我在主题中所说,我希望我的WebView可以防止在另一个活动到达前台时或者当方向发生变化时重新加载网页.之所以是因为WebView内容几乎完全是由Javascript/AJAX生成的.在几个论坛上搜索后,我发现许多人建议使用"saveState"和"restoreState"方法,但是当我查看文档时,它说:
请注意,此方法不再恢复此WebView的显示数据.请参阅savePicture(Bundle,File)和restorePicture(Bundle,File)以保存和恢复显示数据.
所以,我在这里使用了savePicture和restorePicture,如下所示:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Run Code Online (Sandbox Code Playgroud)
......其他一些线......
setContentView(R.layout.main);
mWebView = (WebView) findViewById(R.id.webview);
if (savedInstanceState == null){
loadInicialWebUi();
}else{
mWebView.restoreState(savedInstanceState);
boolean restoredPic = mWebView.restorePicture(savedInstanceState, new File("savedDisplayWebView.temp"));
Log.d(TAG, "restored Picture:" + restoredPic);
}
}
@Override
protected void onSaveInstanceState(Bundle savedInstanceState) {
mWebView.saveState(savedInstanceState);
boolean savedPic = mWebView.savePicture(savedInstanceState, "savedDisplayWebView.temp");
Log.d(TAG, "saved Picture:" + savedPic);
super.onSaveInstanceState(savedInstanceState);
}
Run Code Online (Sandbox Code Playgroud)
而且,这些日志显示它可以保存图片,但无法恢复.我怀疑文件引用可能有一些东西,但我想不出更好的方法来获取保存状态时创建的文件的引用.
有人激动吗?我很感激任何线索/建议.提前致谢.
曼努埃尔.
我使用创建了PostgreSQL数据库转储psql.
现在我想从文件中恢复此备份:
psql -d thesamename -f /my/backup/file
Run Code Online (Sandbox Code Playgroud)
但是我得到数据已经存在的错误.
是否有任何命令从数据库中删除所有内容以使其处于刚刚创建状态,除了再次删除和创建?
(我不想再次设置所有者,tablescpace等)
也许某种方法用备份文件中的那个覆盖数据库?(备份文件来自另一个数据库服务器)
我有一个C#控制台程序,其主要功能应该使用户grep行/列来自日志文本文件。
用户希望在文本文件中的一个示例中重复一组从特定日期等开始的所有相关行。“星期二2004年8月3日22:58:34”到“星期三2004年8月4日00:56:48”。因此,在处理之后,程序将输出两个日期之间在日志文本文件中找到的所有数据。
有人可以提供一些我可以用来grep或创建过滤器以从文件中检索必要的文本/数据的代码的建议吗?谢谢!
C#程序文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
namespace Testing
{
class Analysis
{
static void Main()
{
// Read the file lines into a string array.
string[] lines = System.IO.File.ReadAllLines(@"C:\Test\ntfs.txt");
System.Console.WriteLine("Analyzing ntfs.txt:");
foreach (string line in lines)
{
Console.WriteLine("\t" + line);
// ***Trying to filter/grep out dates, file size, etc****
if (lines = "Sun Nov 19 2000")
{
Console.WriteLine("Print entire line");
}
}
// Keep the console window open in debug …Run Code Online (Sandbox Code Playgroud) 如果我将任意数量的操纵器应用于流,是否有办法以通用方式撤消这些操纵器的应用程序?
例如,请考虑以下事项:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
cout << "Hello" << hex << 42 << "\n";
// now i want to "roll-back" cout to whatever state it was in
// before the code above, *without* having to know
// what modifiers I added to it
// ... MAGIC HAPPENS! ...
cout << "This should not be in hex: " << 42 << "\n";
}
Run Code Online (Sandbox Code Playgroud)
假设我想添加代码MAGIC HAPPENS,将流操纵器的状态恢复到我之前的状态cout << hex.但我不知道我添加了什么操纵器.我怎么能做到这一点?
换句话说,我希望能够写出这样的东西(psudocode/fantasy …
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int square(int a){
return a*a;
}
struct Point{
int x,y;
};
int distance (const Point& a,const Point& b){
int k=(int) sqrt((float)((a.x-b.x)*(a.x-b.x))+((a.y-b.y)*(a.y-b.y)));
return k;
}
int main(){
vector<Point>a(10);
for (int i=0;i<10;i++){
cin>>a[i].x>>a[i].y;
}
int s=0;
int s1;
int k=0;
for (int i=1;i<10;i++){
s+=square(distance(a[0],a[i]));
}
for (int i=1;i<10;i++){
s1=0;
for (int j=0;j<10;j++){
s1+=square(distance(a[i],a[j]));
if (s1<s) { s=s1; k=i;}
}
}
cout<<k<<"Points are:";
cout<<a[k].x;
cout<<a[k].y;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我有以下代码,但这里是错误列表
1>------ Build started: Project: distance, …Run Code Online (Sandbox Code Playgroud) c++ compiler-errors using-directives overload-resolution name-lookup
我很好奇是否有办法通过W3C DOM创建DocType节点?该规范明确指出它们是只读的并且无法编辑,但它们是否能够被创建?
http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-412266927
Document接口似乎没有任何create方法:
也许更广泛的问题是:可以通过DOM以编程方式构建全新的HTML文档吗?我知道document.createDocumentFragment()但我的意思是相当于具有特定doctype的根HTML文档等.
更新:它看起来像最近的Gecko和WebKit实现DOMImplementation.createDocument,DOMImplementation.createDocumentType但不是IE8或之前(没有检查IE9).所以很遗憾,我仍然被困在那里.
我也有点不确定一旦拥有它,我可以用这个新的Document实例做什么.所有当前的DOM方法都挂起了全局文档对象,所以似乎没有办法将它与新的交换.
我正在尝试将所选的默认浅灰色突出显示更改为聚焦ListViewItem时显示的蓝色突出显示ListView.我一直在努力在线调和不同的StackOverflow答案和来源,但我还没想出我还需要什么样的XAML.我有以下内容:
<ListView ItemContainerStyle="{StaticResource checkableListViewItem}"
SelectionMode="Multiple"
View="{StaticResource fieldValueGridView}"/>
Run Code Online (Sandbox Code Playgroud)
引用的View资源是:
<GridView x:Key="fieldValueGridView" AllowsColumnReorder="False">
<GridViewColumn Header="Field">
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock FontWeight="Bold" Text="{Binding Path=DisplayName}"/>
<TextBlock FontWeight="Bold" Text=": "/>
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Value" DisplayMemberBinding="{Binding Path=FieldValue}"/>
</GridView>
Run Code Online (Sandbox Code Playgroud)
引用的ItemContainerStyle资源是:
<Style TargetType="ListViewItem" BasedOn="{StaticResource {x:Type ListViewItem}}"
x:Key="checkableListViewItem">
<Setter Property="IsSelected" Value="{Binding Path=IsChecked}" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Top" />
</Style>
Run Code Online (Sandbox Code Playgroud)
的ListView的IsEnabled属性不会改变,如果该事项.我想以某种方式合并<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="{x:Static SystemColors.HighlightColor}"/>,或类似的东西,以突出显示ListViewItem未聚焦的选定的ListView.
我有以下风格,但这似乎并没有影响ListViewItem …
我是Java的新手:)
我有2个字符串列表,我想知道什么是最有效的方法来比较两个,并有一个结果数组,其中包含不在另一个中的字符串.例如,我有一个名为oldStrings的列表和一个名为Strings的列表.我已经看过Comparator函数但是没有完全理解它是如何工作的,现在我以为我可以创建一个for循环,循环遍历每个字符串然后保存该字符串:
for (final String str : oldStrings) {
if(!strings.contains(str))
{
getLogger().info(str + " is not in strings list ");
}
}
Run Code Online (Sandbox Code Playgroud)
此列表中最多可包含200个字符串.这是最好的解决方法吗?谢谢!
public class TabbedArea extends JTabbedPane {
public void addArea(){
add(component);
final JPanel panel = new JPanel(new BorderLayout());
panel.add(new JLabel(title), BorderLayout.LINE_START);
JButton closeButton = new JButton(new CloseIcon());
closeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
removeArea(subAreas.get(indexOfTabComponent(panel)));
}
});
panel.add(closeButton, BorderLayout.LINE_END);
setTabComponentAt(getTabCount() - 1, panel);
}
}
public class LnFManager {
public void setTheme(PlasticTheme theme){
for (Window window : Window.getWindows()) {
if (window.isDisplayable())
SwingUtilities.updateComponentTreeUI(window);
}
}
}
Run Code Online (Sandbox Code Playgroud)
调用setTheme()时,会导致重复发生(大概是每个组件):
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.plaf.basic.BasicTabbedPaneUI.scrollableTabLayoutEnabled(BasicTabbedPaneUI.java:263)
at javax.swing.plaf.basic.BasicTabbedPaneUI.access$400(BasicTabbedPaneUI.java:54)
at javax.swing.plaf.basic.BasicTabbedPaneUI$TabContainer.doLayout(BasicTabbedPaneUI.java:3850)
at java.awt.Container.validateTree(Container.java:1568)
at …Run Code Online (Sandbox Code Playgroud)