技術者派遣の技術日誌ブログ

September 23, 2008

DotNetSlackers: Using HttpModule to handle Ajax calls.

Filed under: ADO.NET, ALL, Ajax, C# — Tags: , , , , — doku @ 12:00 am

,ASP.NET,JAVASCRIPT,JQUERY

Using HttpModule to handle Ajax calls.

Using HttpModule to handle Ajax calls. Posted by: The Code Project Latest Articles, on 23 Sep 2008 | View original | NEW Bookmarked: 0 time(s). Using HttpModule to handle Ajax calls in C#… Advertisement …

Go here to see the original:
DotNetSlackers: Using HttpModule to handle Ajax calls.

September 17, 2008

[.NET] WindowsIdentity.GetCurrent と Thread.CurrentPrincipal

Filed under: .NET Framework, C# — Tags: , , , , — Sayuri @ 7:19 pm

今まで同じものだと思ってた。 ( WindowsIdentity と IPrincipal の違いは置いといて。)
それぞれ違うユーザー情報を返してきた時は驚いた。

WindowsIdentity クラス (System.Security.Principal)GetCurrent メソッド
現在実行中の Win32 スレッドのセキュリティ コンテキストの ID 情報を返します。

Thread クラス (System.Threading)CurrentPrincipal プロパティ
Win32 スレッドの上位で、現在実行されている .NET スレッドのプリンシパルを返します。

なるほど、型の違いと、Thread.CurrentPrincipal だけが設定可能なのはこういう理由か。

[ 参考 ]
ASP.NET ID マトリックス
.NET Framework のユーザー操作の基礎

September 16, 2008

Use JavaScript to enable formatting of Data View UI controls …

Filed under: ALL, Ajax, JAVA — Tags: , , , , , , — doku @ 9:43 pm

Note: In this article, some of the material that explains how to perform the more basic tasks is hidden from view by default if you have JavaScript turned on. If you want to print this article with all the material included, …

Note: In this article, some of the material that explains how to perform the more basic tasks is hidden from view by default if you have JavaScript turned on. If you want to print this article with all the material included, …

Note: In this article, some of the material that explains how to perform the more basic tasks is hidden from view by default if you have JavaScript turned on. If you want to print this article with all the material included, …

Note: In this article, some of the material that explains how to perform the more basic tasks is hidden from view by default if you have JavaScript turned on. If you want to print this article with all the material included, …

Note: In this article, some of the material that explains how to perform the more basic tasks is hidden from view by default if you have JavaScript turned on. If you want to print this article with all the material included, …

Go here to read the rest:
Use JavaScript to enable formatting of Data View UI controls …

[ .NET ] .NET Framework コンストラクタを呼び出さずにインスタンス化

Filed under: C# — Tags: , , , , , — Shotalow @ 1:21 pm

通常、インスタンスを生成する際には必ずコンストラクタが呼び出されます。
でも実は、コンストラクタを実行せずにインスタンスを生成することができます。

方法はとても簡単です。
生成したいインスタンスの型情報を渡して FormatterServices クラス (System.Runtime.Serialization)GetUninitializedObject メソッド を呼び出すだけです。
このクラスは、通常シリアル化で使用されるクラスですが、インスタンス化したいクラスに SerializableAttribute クラス (System) が付加されている必要はありません。
それと面白いことに、Void 構造体 (System) をインスタンス化することができます。 (Activator じゃできないのに)
ただし、String クラス (System)ContextBoundObject クラス (System) はこの方法でインスタンス化することができません。

下記のコードでは、コンストラクタの処理中に例外をスローするクラスのインスタンスを生成できることが確認できます。

using

September 14, 2008

[ .NET ] .NET Framework VB の RaiseEvent アクセサの問題点

Filed under: .NET Framework, ALL — Tags: , , , , , — Sayuri @ 7:23 pm

とりこびとさんの記事を読んでいて、そういえば VB のイベント定義って C# と違うんだよなぁと思い出したことがきっかけで、久々に VB のコードを書いてみました。そしたら、ちょっとした問題に気づきました。

とりあえず、C# でのイベント定義から。
C# でイベントを定義する場合、通常は以下のように記述します。

public

September 11, 2008

【Javascript】JavaScriptでのOOP

Filed under: ALL, Javascript/Xhtml/Css — Tags: , , , , , , , — Sayuri @ 1:42 pm

JavaScriptはオブジェクト指向言語である。
ただし、”クラスベース”のオブジェクト指向言語 ( C#やJavaなど ) ではなく、”プロトタイプベース”のオブジェクト指向言語である。

以下、JavaScriptでのOOPについての簡単な解説。

【 コンストラクタ 】
オブジェクトの雛形は ” コンストラクタ ” と呼ばれる関数として定義する。これは、クラスベース オブジェクト指向言語の ” クラス ” に相当する。コンストラクタは関数なので、普通の関数と同じように呼び出すこともできる。 ( 普通、そんな使い方はしないけど。 )
コンストラクタからオブジェクトを生成するには、new 演算子を用いる。
//

【 .NET 】【 C# 】コーディング俺規約 – usingブロックとreturn

Filed under: C# — Tags: , , , — doku @ 1:39 pm

何かと言うと、usingブロック内で得た値を戻り値で返す場合です。
例えば、

public

【Javascript】HTML や ASPX と対になる JS ファイルの書き方

Filed under: Javascript/Xhtml/Css — Tags: , , , , , , , — Sayuri @ 10:11 am

最近、というか今日から、HTML や ASPX と対になる JS ファイルの書き方を変えてみた。
こんな感じ。

HogePage.js
//

September 10, 2008

【Tips】スレッド内で発生した例外 – System.Timers.Timer

Filed under: C# — Tags: , , , , , — Shotalow @ 12:47 pm
では、System.Timers.Timerを使った非同期処理の場合はどうなるんだろうか?
この Timerもスレッドが生成されるので、同じ動きだろうか?

public static void Example() {
System.Timers.Timer tm = new System.Timers.Timer();
tm.Elapsed += new System.Timers.ElapsedEventHandler(tm_Elapsed);
tm.Interval = 1000;
tm.Enabled = true;
Console.ReadLine();
Console.WriteLine("end");
}
static void tm_Elapsed(object sender, System.Timers.ElapsedEventArgs e) {
try {
Console.WriteLine("Hello World!");
Thread.Sleep(1010);
throw new Exception("1");
} finally {
Thread th = Thread.CurrentThread;
Console.WriteLine(
th.ManagedThreadId + " " +
th.IsThreadPoolThread);
}
}

というコードで試してみる。
あえて、tm.Interval よりも、em_Elapsed メソッドの方が時間がかかるようにしてある。

これを実行すると、今までのプログラムと違って、強制終了されない。
このコードを動かすと、当然だが、IsThreadPoolThread は、常に trueだ。
一方、ManagedThreadId は、4,5,6の値が何度も表示され、7以上の値が表示されることはない。

スレッド内で例外を処理しなくても、スレッドが自動的にスレッドプールに返却されているようだ。

さらに、興味深い?のは、AppDomain.UnhandledExceptionで例外がキャッチできないことだ。tm_Elapsed 内で未処理の例外があると、この例外は行方不明になってしまう。

これまでの結論は、AppDomain.UnhandledExceptionで は使えないってこと。

それと、繰り返しになるが、Timerの場合は、例外をキャッチしなくてもプログラムが強制終了してしまうことは無い。
一方、Threadの場合は、強制終了されてしまう。
この2つの違いは、スレッドプールと、通常のマニュアルスレッドの違いから来るのかな?
それとも、Timer独自の仕様なのだろうか?

ThreadPool.QueueUserWorkItem や DelegateのBeginInvoke についても調べないといけないな。

[How to]Dispose(bool disposing) の override

Filed under: C# — Tags: , , , , , — Sayuri @ 12:24 pm

http://msdn2.microsoft.com/en-us/library/fs2xkftw.aspx
のコードをみて、以下のように書いたら、base.Dispose() が呼ばれない可能性があるということで、FxCopの警告が出た。

   protected override void Dispose(bool disposing) {
if(!this.disposed)  {
try {
if(disposing)  {
addedManaged.Dispose();
}
this.disposed = true;
} finally {
base.Dispose(disposing);
}
}
}

なので、以下のように書き換えた。

   protected override void Dispose(bool disposing) {
try {
if(!this.disposed)  {
if(disposing)  {
addedManaged.Dispose();
}
this.disposed = true;
}
} finally {
base.Dispose(disposing);
}
}

この場合は、base.Dispose(true)が複数回呼ばれる可能性がある。でも基底クラスのDispose()もパターンに則って書かれているはずだから、問題はでないはず…
僕の好みは、前者なんだけど、まあいいか。

Older Posts »

このページの上部に戻る

Powered by WordPress