我在我正在工作的项目中使用Tinymce(使用jQuery); 我们使用富文本编辑器供用户输入信息; 但是,有时加载页面时Firefox和Chrome会检测到"未定义的错误"错误(有时在代码的不同行),而其他时候页面加载就好了.奇怪的是,它与IE完美配合.
这是我正在使用的一些代码:
view.find('textarea.rich-text').each(function () {
$(this).tinymce( /* ...rules... */);
});
Run Code Online (Sandbox Code Playgroud)
后来
_variable.find("#summary").tinymce().setContent(content);
Run Code Online (Sandbox Code Playgroud)
此行是错误(有时)被捕获的地方.在我看来,问题是一个加载问题,即使tinyMCE插件在此行之前初始化约5000行.
更新:现在我已经设法用setTimeout"解决"问题了,但这似乎是一种非常丑陋的方式.
我一直在玩Exceptions以了解我应该如何正确使用它们.到目前为止,我知道throw保持原始堆栈跟踪; throw new CustomException(...)通常用于想要添加有关发生的异常的更多信息或添加/更改消息,甚至更改异常本身的类型; 并且throw ex永远也不会被使用,除非我不想失去原来的堆栈跟踪.
所以我编写了一个小程序,我可以在原始消息中添加内容时多次捕获并重新抛出异常.
public class Sample
{
static void Main(string[] args)
{
new Tester().FirstCall();
}
}
public class Tester
{
public void FirstCall()
{
try
{
SecondCall();
}
catch (Exception e)
{
Console.WriteLine(e.StackTrace);
Console.WriteLine(e.Message);
}
}
public void SecondCall()
{
try
{
ThirdCall();
}
catch (GoodException ex)
{
throw new Exception(ex.Message, ex);
}
}
public void ThirdCall()
{
try
{
FourthCall();
}
catch (ArithmeticException ae)
{
throw new GoodException("Arithmetic mistake: " …Run Code Online (Sandbox Code Playgroud) 我有一个运行两种方法的Windows服务; 一个人使用该Ae.Net.Mail库每5分钟从三个电子邮件帐户中读取未读电子邮件(我们称之为EmailParserWorker),另一个方法每30分钟另一个未指定的工作.因为这些方法必须每X次运行一次,所以我用a Timer来管理它们,它们工作正常.
private Timer mailParserTimer;
private readonly TimeSpan SLEEP_TIME_MAIL_PARSER = TimeSpan.FromSeconds(300d);
/*...*/
public MyService()
{
ServiceName = _serviceName;
mailParserTimer = new Timer(new TimerCallback(EmailParserWorker), null, Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan);
}
public void StartService()
{
mailParserTimer.Change(SLEEP_TIME_MAIL_PARSER, Timeout.InfiniteTimeSpan);
//EmailAnalyzer is a custom class I use to manage the accounts
ea1 = new EmailAnalyzer(Config1);
ea2 = new EmailAnalyzer(Config2);
ea3 = new EmailAnalyzer(Config3);
}
protected void EmailParserWorker(object state)
{
try
{
// Pause timer during processing so it won't be run twice if …Run Code Online (Sandbox Code Playgroud) 我环顾四周,但之前似乎没有人问过这个问题,所以在这里.
我正在开发一个具有IEquatable接口的自定义类,因此我正在创建自己的Equals方法.这是它的样子:
public bool Equals(QueryFilter qfilter)
{
if (qfilter == null)
{
return false;
}
return ((this.Value.Equals(qfilter.Value)) &&
(this.Name.Equals(qfilter.Name)) &&
(this.Order == qfilter.Order));
}
Run Code Online (Sandbox Code Playgroud)
其中Value,Name和Order是QueryFilter类的字段.值和名称是strings,但Order是一个int,我想知道使用==运算符是否正常,或者我是否应该使用该Int32.Equals方法,以"匹配"其他字段如何进行比较?我检查了MSDN,但它没有详细说明,只是说它超载了,但我不确定在这种情况下这意味着什么.那==将是唯一一个在工作的人吗?
总而言之,哪一个更好?Int32.Equals还是==?我什么时候应该使用每一个?
假设我有一个SQL Server数据库,在其他表中有一个名为的表Mail,它具有与之关联的预期收件人,发件人,邮件正文等,其中一个是属性Priority,它基本上表明邮件是否有被发送的高,正常或低优先级.因为我将只使用这些少量的值(如果要添加更多的值,那就不会那么多),我决定将优先级设为tinyint类型,而在我的代码中,我代表的是一种enum类型.
我的问题是,在调用数据库时插入和检索此属性的正确方法是什么?在检索(使用a DataRow)的情况下,我有:
mail.Priority = (MailPriority)(byte)row["Priority"];
Run Code Online (Sandbox Code Playgroud)
并插入:
parameter = new SqlParameter("@Priority", SqlDbType.TinyInt);
parameter.Value = (byte)mail.Priority;
statement.Parameters.Add(parameter);
Run Code Online (Sandbox Code Playgroud)
(其中声明是a SQLCommand).
这样做会有效吗?这是正确的方法吗?我认为使用tinyint是可以的,因为可能的值不能那么多,但我不知道是否int会好,在性能方面更好,或者更常用,等等.
我创建在Visual Studio 2010中使用C#中的窗口服务,我有几个方法,比如Add,Multiply和其他人,我敢投入的onStart方法.现在,我希望这些方法每五分钟运行一次.那么后台工作者流程如何帮助我呢?
protected override void OnStart(string[] args)
{
add(); // yes, it doesn't have parameters
}
Run Code Online (Sandbox Code Playgroud)