Self-modified code? Theoretically speaking, this is possible, but this is extremely complex (not only on .NET), so I don't want even to discuss it; but I'll mention in brief: you could create separate Application Domain, in this Domain create and load a whole assembly ether using
System.Reflection.Emit
(and in this case you also should know MSIL pretty well) or generate the code and compile it using CodeDOM, work with this Domain through IPC, and, when you need to do it again, unload the whole Application Domain and create a new one. How many of those concepts are you confident with? It will require very good knowledge and confidence in all of these topics, and also debugging is pretty difficult.
However, I think you don't need all these esoteric stuff right now, which is uses in some rare and really advanced cases. I rather think your question is based on misconceptions about very basic and simple programming principles. All the modern programming paradigms are based on stored and read-only code, separation between code and data, etc. It goes back to history as far as the
Turing machine, which was not yes a
stored-program computer.
Please see:
http://en.wikipedia.org/wiki/Turing_machine[
^],
http://en.wikipedia.org/wiki/Stored-program_computer[
^].
See also:
http://en.wikipedia.org/wiki/Self-modifying_code[
^].
Nevertheless, if we go to mainstream programming, there a fields where modification or generation of code is widely used, but usually this is not a true self-modified code (which is, again, is discouraged). In particular, it happens in ASP.NET and other Web technologies. But this is completely different thing, because generating and generated codes work on the Web on different levels and different tiers. In brief, the server-side code responds to HTTP request and sends an HTTP response with some document like HTTP (most typically), which may contain JavaScript code which is then is executed on client side. This simple mechanism is often misunderstood by CodeProject inquirers who ask how to call JavaScript code by in C#/VB.NET code and visa versa. Strictly speaking, it makes no sense.
First of all, I doubt you really need the timer. You need to explain what effect do you expect and, importantly, why.
It's hard to understand what exactly you are trying to achieve, but I can suggest that it can be done using regular and usual ASP.NET and JavaScript techniques which you simply need to learn. Perhaps after that you will be able to ask more specific questions.
—SA