我从我看到的一个例子中做到了这一点,它从未抛出任何错误,但图像显示为灰色.
有一个更好的方法吗?
private unsafe void menuItem7_Click(object sender, EventArgs e)
{
var settings = Utility.GatherLocalSettings();
openFileDialog1.InitialDirectory = settings.SavePath;
openFileDialog1.Filter = "Scan Files (*.jpg)|*.jpg";
openFileDialog1.FilterIndex = 1;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
byte[] openFile = File.ReadAllBytes(openFileDialog1.FileName);
fixed (byte* p = openFile)
{
IntPtr img = (IntPtr)p;
frmContainer newScan = new frmContainer(img);
newScan.MdiParent = this;
newScan.Text = Path.GetFileName(openFileDialog1.FileName) + " [Saved]";
newScan.Show();
}
}
}
Run Code Online (Sandbox Code Playgroud)
PS:我检查了csproj以允许构建中的不安全代码.
我刚开始在一个网站上工作,这将帮助人们了解说唱歌手在谈论什么.用户将看到一首说唱歌曲的歌词,他们将能够点击某些歌词来查看解释.这是一个截图(你也可以在这里查看网站):
alt text http://img146.imageshack.us/img146/6882/clocal.png
(原始歌词审查; 点击这里查看)
无论如何,我的问题是如何在我的应用程序中建模这些注释.现在,我将歌词和注释存储为这种格式的一大块HTML:
<div class="lyrics">
With the goons I spy
<a href="#note1">Stay in tune with ma</a>
<a href="#note2">She like damn
This the realest since 'Kumbaya'</a>
Kumbayay Killa Cam my lord
</div>
<div class="annotations">
<div id="note1">
"Ma" refers to ladies, generally, and specifically also the woman singing the hook; "Stay in tune" is a musical metaphor: he literally stays in tune with the singer and also in the sense that he has game.
</div> …Run Code Online (Sandbox Code Playgroud) 为 ASP.NET 应用程序创建依赖注入容器是很常见的,这样它就可以与应用程序一起生存。
我在每个请求中创建 DI 容器,并在请求结束时释放它。
主要目的是任何 DI 容器在容器被释放时都支持释放对象。
另外:如果我需要在请求之间共享资源(NHibernate SessionFactory),我只需将它们保存在静态变量中,并将该值封装在每个请求的对象中。像这样:
public class SessionFactoryAggregator : ISessionFactory {
static ISessionFactory actualFactory;
// Implement ISessionFactory and proxy calls to the actualFactory
}
Run Code Online (Sandbox Code Playgroud)
这只是模拟的单例模式。
我的问题:
更新:目前我通过自己的 DI 提供程序抽象使用 Castle Windsor,因此实际容器是可插入的。
谢谢。
我想VACUUM在Perl上的SQLite数据库上的某个时间做,但它总是说
DBD :: SQLite :: db失败:无法在事务中使用VACUUM
那我该怎么做?
my %attr = ( RaiseError => 0, PrintError => 1, AutoCommit => 0 );
my $dbh = DBI->connect('dbi:SQLite:dbname='.$file'','',\%attr)
or die $DBI::errstr;
Run Code Online (Sandbox Code Playgroud)
我在用AutoCommit => 0.而错误发生在:
$dbh->do('DELETE FROM soap');
$dbh->do('DELETE FROM result');
$dbh->commit;
$dbh->do('VACUUM');
Run Code Online (Sandbox Code Playgroud) 有关创建数据库表的文档说:
另一个选择是在创建表之前使用MySQLdb的init_command选项:
DATABASE_OPTIONS = {
"init_command": "SET storage_engine=INNODB",
}
Run Code Online (Sandbox Code Playgroud)
这会在连接到数据库时设置默认存储引擎.创建表后,应删除此选项,因为它只在表创建期间向每个数据库连接添加一个查询.
有谁知道为什么有必要在创建表后删除此选项?
在C#中合法和安全地捕获一个线程上的异常,然后将其重新抛出到另一个线程上.
这是合法的
Exception localEx = null;
Thread mythread = new Thread() { () =>
{
try
{
DoSomeStuff();
}
catch(Exception ex)
{
localEx = ex;
}
});
myThread.Start();
...
myThread.Join();
if(localEx != null)
throw localEx; // rethrow on the main thread
Run Code Online (Sandbox Code Playgroud)
我认为这是合法的,但我很难找到证明它的任何doco.我发现最接近的是在线程之间传递异常的简短提及:http://msdn.microsoft.com/en-us/library/ms229005.aspx
我使用-insertRowsAtIndexPaths:withRowAnimation将一些行插入到表中,我希望从左侧缩进行以将它们与其余单元格区分开来.UITableViewCell的indentationLevel属性看起来就像我需要的那样,但似乎没有做任何事情.这是我用来设置缩进级别的代码(点语法没有区别):
[cell setIndentationWidth:10];
[cell setIndentationLevel:1];
Run Code Online (Sandbox Code Playgroud)
缩进级别是我想要的,还是我应该在其他地方寻找?
我正在教自己php的开始.我正在给自己微观项目推动自己.
到目前为止,我有一个MYSQL数据库,通过php表单创建.一栏是因果报应.我将数据库表的值显示在html表中,并且在每行的末尾,我想点击一个超链接,让我们说一个加号,将该行的业力级别增加1.然后加号会消失.
我应该每行都有一个自动增量整数作为主键.
我想知道是否有任何方法可以从java servlet访问环境变量.我知道我可以使用web.xml将params传递给servlet但是我需要在运行时传递一些值.
要求是这样的 -
在服务器端运行的非基于Web的应用程序设置一些值(环境变量),并且必须在Web会话期间(来自servlet)访问它.我正在使用apache web服务器.
我是基于网络编程的新手,所以如果我问一些愚蠢/愚蠢的话,请原谅我.
我正在玩linux网络编程,我写了一个小客户端服务器应用程序,它在客户端和服务器进程之间弹出一条小消息并测量往返时间.我一直看到大约80ms的localhost往返(这是在连接设置之后).这似乎非常高.在Vista上,运行相同代码的同一台机器的时钟频率将大大低于1ms.
关于这种差异可能来自哪里的任何想法?代码非常简单,一端接受,另一端连接,然后通过对等套接字发送/接收.
我只是开始Linux,如果这是一个愚蠢的问题,道歉.