|
Technically, isn't C# code complied at run time?
/\ |_ E X E GG
|
|
|
|
|
|
Hi guys, I 've made a simple program that access a resource and read and write it. The program works fine, but I would like to know if my code is good or there is a better way to do the same.
Thanks a lot for helping me :->
using System;
using System.Collections;
using System.Threading;
namespace ReadersAndWriters
{
///
/// Summary description for Class1.
///
public class BookSeats
{
private bool bAccess = true;
public SortedList Seats = new SortedList();
public BookSeats()
{
for(int i = 0 ; i <= 9 ; i++)
{
Seats.Add(i, 0);
}
}
public int this[int iIndex]
{
get
{
if(!bAccess)
{
Monitor.Wait(this);
}
return (int) Seats[iIndex];
}
set
{
if(bAccess)
{
bAccess = false;
lock(this)
{
Seats[iIndex] = value;
bAccess = true;
Console.WriteLine("Thread {0} acionada", Thread.CurrentThread.Name);
Monitor.Pulse(this);
}
}
else
{
Monitor.Wait(this);
}
}
}
}
public class Client
{
private Random rGen = new Random();
private int iSeat = 0;
private BookSeats m_BookSeats;
public Client(BookSeats Seats)
{
m_BookSeats = Seats;
iSeat = rGen.Next(0, 9);
}
public void MakeReservation()
{
m_BookSeats[iSeat] = 1;
}
public void CancelReservation()
{
m_BookSeats[iSeat] = 0;
}
public void QueryReservation()
{
for(int i = 0 ; i < m_BookSeats.Seats.Count ; i++)
{
if(m_BookSeats[i] == 0)
{
Console.WriteLine("Thread {0} lendo", Thread.CurrentThread.Name);
}
else
{
Console.WriteLine("Lugar reservado");
}
}
}
}
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
BookSeats Seats = new BookSeats();
Client ClientOne = new Client(Seats);
Client ClientTwo = new Client(Seats);
Thread ClientOneMR = new Thread(new ThreadStart(ClientOne.MakeReservation));
ClientOneMR.Name = "Reserva Cliente 1";
Thread ClientTwoMR = new Thread(new ThreadStart(ClientTwo.MakeReservation));
ClientTwoMR.Name = "Reserva Cliente 2";
//Thread ClientOneCR = new Thread(new ThreadStart(ClientOne.CancelReservation));
//ClientOneCR.Name = "Cancela Cliente 1";
//Thread ClientTwoCR = new Thread(new ThreadStart(ClientTwo.CancelReservation));
//ClientTwoCR.Name = "Cancela Cliente 2";
Thread ClientOneQR = new Thread(new ThreadStart(ClientOne.QueryReservation));
ClientOneQR.Name = "Consulta Cliente 1";
Thread ClientTwoQR = new Thread(new ThreadStart(ClientTwo.QueryReservation));
ClientTwoQR.Name = "Consulta Cliente 2";
ClientOneMR.Start();
ClientTwoMR.Start();
//ClientOneCR.Start();
//ClientTwoCR.Start();
ClientOneQR.Start();
ClientTwoQR.Start();
}
}
}
|
|
|
|
|
I am trying to create a database with specific DataFiles and LogFiles in C#. For the life of me I can not figure out how to write the statement for the Datafile part. I found some VB6 code on the Microsoft web site and am having diffuculty converting this line:
-----------------------------------------------------------
oDatabase.FileGroups("PRIMARY").DBFiles.Add oDBFileData
-----------------------------------------------------------
Here is the complete code:
Dim oDatabase As New SQLDMO.Database
Dim oDBFileData As New SQLDMO.DBFile
Dim oLogFile As New SQLDMO.LogFile
oDatabase.Name = "Northwind"
' Define the PRIMARY data file.
oDBFileData.Name = "NorthData1"
oDBFileData.PhysicalName = "c:\program files\microsoft sql server\mssql\data\northwnd.mdf"
oDBFileData.PrimaryFile = True
' Specify file growth in chunks of fixed size for all data files.
oDBFileData.FileGrowthType = SQLDMOGrowth_MB
oDBFileData.FileGrowth = 1
oDatabase.FileGroups("PRIMARY").DBFiles.Add oDBFileData
' Define the database transaction log.
oLogFile.Name = "NorthLog1"
oLogFile.PhysicalName = "c:\program files\microsoft sql server\mssql\data\northwnd.ldf"
oDatabase.TransactionLog.LogFiles.Add oLogFile
' Create the database as defined. Note: Create and connect of SQLServer
' object used is not illustrated in this example.
oSQLServer.Databases.Add oDatabase
Thanks in advance for your help
SAG, CANADA
|
|
|
|
|
Hi, i want to make an installer for a executable file, that can install my program in the computer, can any one guide me.thankx
|
|
|
|
|
You can find a lot of free installer programs on the WWW.
The easiest way is create the "setup" in WinRar or WinZip. The noder easy way is to create a Setup project in VS.NET
And I suggest you some installer program, I use:
- QSetup (it's good because can test target machine for Framework)
- Install Shield (good, but complicate and must pay a lot for it)
- Inno Setup (good, and as I remember it's free)
- Setup2Go (good, and as I remember it's free)
That's all I can help you.
|
|
|
|
|
Visual Studio .NET 2003 comes with an Installer project type. If all you want to do is put the application where the user wants to and have a desktop/Programs menu link, then it will do fine. Look for "Setup And Deployment Projects" in the New Project dialog.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
thanks for ur reply, actually i wanat to make my own installer program,using c# code.what should i do to make such a program. thanks
|
|
|
|
|
When i try to open a PNG File (or other format) with 8bpp color depth then C# sets the PixelFormat of the Bitmap-Class always to the 32bppARGB PixelFormat. But this Bitmap consumes twice as much memory as normally needed for a 32bpp Bitmap. For example:
Loading a grayscale .PNG with 2048x1536x8bpp = 3 MB:
Bitmap bmp = new Bitmap(Image.FromFile("test.png"));
in C# this consumes 24 MB of memory for a File that "should" consume 3 MB?
=(2048x1536x32bpp) x 2?? Why?
Is there a way to open an image file with the original PixelFormat? In case of this .png it should be 8bppIndexed...
Regards
|
|
|
|
|
|
i meassure it by single stepping throught my code and simply calculating the before and after memory consumation. There i can clearly see that my programm takes 8 times more memory for the file than it should do.
I would understand if the programm takes 4 times more memory because the file has 8bpp and the C# Bitmap Class converts it to 32bppARGB. But it uses 8 times more, why? Is it internally converted to 48bit?
And the main question is, how to open without having the Bitmap set to 32bppARGB mode?
|
|
|
|
|
Once again, where are you getting these measurements from?
Alpini wrote:
memory consumation
Measured by what? Don't tell me - Task Manager? It's NOT showing you what your application is actually using. This is the memory that the .NET Framework Memory Manager has set aside for your app, not what your app is actually using.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
sure, the Taskman is not the best way for meassuring memory consumation... But... thats not my question, the main thing I want to know is, why does the Bitmap class open a 8bpp Grayscale image in 32bitARGB mode? And if i can prevent this? It would be best if i would be able to open such files from the beginning in the 8bppIndexed Pixelformat. If it is not possible to open it this way, i have to convert it manually to 8bppIndexed, but how?
One other thing regarding the Taskmanager, when i open the same image using Image img = new Image.FromFile("") it is also converted to 32bitARGB, but you can clearly see, that the Taskman shows the right increase in memory usage for this file in 32bppARGB mode and not the double size...
(I hope you can understand my question, i have to deal with my shool-english only)
|
|
|
|
|
Hi all,
I'm trying to use the mouse wheel for different controls inside my form.
The only way that i found that is possible is to move the focus from one control to the other, by pressing the mouse button.
I have noticed that in Microsoft Outlook, you can scrool by using the mouse wheel, by only moving the mouse pointer to the desirable control, and the focus does not change.
Does anybody know how you can use scrollling with the mouse wheel with out loosing focus on the other control???
Thanks,
Omer.
|
|
|
|
|
Anonymous wrote:
Does anybody know how you can use scrollling with the mouse wheel with out loosing focus on the other control???
Well, that's some pretty fancy stuff. You would need to capture mouse events at the form level and either your form would need a way of communicating the mouse gesture to the control, or the control has to hook an event that the form provides. Either way, the form is also going to need to identify the control that the mouse is hovering over and send the event to the appropriate control or the control will have to check if the mouse is hovering over itself. This all actually easily doable but you'll have to think about your architecture a little bit. This isn't something you can get working just from the designer!
Marc
My website
Latest Articles:
Object Comparer
String Helpers
|
|
|
|
|
Can anyone tell me how to write an addin.
what are the roles of Onconnect, Exec, EnvDTE, ...
How to debug and Addin project
How to setup.
|
|
|
|
|
|
hi all,
I am trying to change databse for a report.It has MS Access data connection by default.I am trying to chage to sybase through odbc.I follow the same steps recomeded by crystal report's web site..it seems not working...
any one can help on this...
thanks in advance..
code for you refer...alwys displaying connection error...
CrReportDoc.SetDatabaseLogon("dba","sql","posdataodbc","tmpdata");
CrConnInfo.ServerName="posdataodbc";
CrConnInfo.DatabaseName ="tmpdata";
CrConnInfo.UserID="dba";
CrConnInfo.Password="sql";
CrTables=CrReportDoc.Database.Tables; ;
for(int i=0;i<=CrTables.Count-1;i++)
{
CrTableLogoninfo = new TableLogOnInfo();
CrTable = CrTables[i];
CrTableLogoninfo = CrTable.LogOnInfo;
CrTableLogoninfo.ReportName =CrTable.LogOnInfo.ReportName;
CrTableLogoninfo.ConnectionInfo= CrConnInfo;
CrTable.ApplyLogOnInfo(CrTableLogoninfo);
CrTableLogoninfo = CrTable.LogOnInfo;
if(!CrTable.TestConnectivity())
{
System.Windows.Forms.MessageBox.Show("Error Connection");
return false;
}
CrTables[i].Location = "DBA." + CrTableLogoninfo.TableName;
}
break;
Jeyapandian Kb.
|
|
|
|
|
I'm working on a custom drawn ListView and when scrolled horizontally
it does not redraw itself. I couldn't find a scroll event in the FCL
reference and in the Windows Shell controls reference either. How could
I force redrawing when the control is scrolled horizontally?
|
|
|
|
|
I've been using C# for a long time. But one day, a friend ask me, what is the difference between them. I can't answer.
So, can anybody help me answer this little question?
|
|
|
|
|
Well, it is the one magical thing that grabbed me a few years ago
when I was reading a thin book about the C# language
The public field is just a variable that you can read and write
without any control. I mean that you can set the field any value
that is possible for the type of the field. And that's pretty much
it.
While the property is a more complex thing - it appears to be a
public variable but it's a totally different thing. A property is a
set of one or two functions in fact (accessor and/or modificator).
For example, assume that we have the "public string Name" property.
When the compiler generates the IL code, it generates also
one or both of the following functions:
public string get_Name() { the_statements_in_the_get_function; }
public void set_Name(string value) { the_statements_in_the_set_function; }
And you can do anything inside. Getting the value of a property
calls the get_Name function, and setting a value to the property
calls the set_Name function. That's pretty powerful, 'cause you can
do many more things than return/set the actual variable beneath (if
there is one) - you can raise events, force redraw etc.
And of course, we should thank Delphi for this nice language feature
Cheers!
|
|
|
|
|
Hello
If you'll look at COM, you will see, that defining a property for an object leads to appearing of two functions: get_PropertyName and put_PropertyName . In C++ you will use these functions to access the property value, in VB you can work with the property "directly" (obj.PropertyName ).
In C# is similar. There are two accessors set and get . And you can perform whatever calculation you want inside them.
Andrew
|
|
|
|
|
|
Actually, the two definitions that you got missed off something very important. You should never make a field public because it blows a great big hole the encapsulation aspect of OO.
Even if you just want direct access to a field in a class, you should wrap it in a property in order to future proof it against possible changes. At the moment you may only need to set the field underneath the property. But in future you may need to tell other objects about the change. If you were just accessing the field directly then you couldn't add this functionality easily.
My: Blog | Photos
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More
|
|
|
|
|
Yes, yes! That's very important! Never expose a field publically
unless it is a readonly or const. But you even can do it for them too.
The only case that I use public fields in, is when deriving from EventArgs.
I put some data as public readonly fields to reduce the code and to
speed up the handling a little bit.
And if you look up the FCL reference, there's almost no public fields exposed,
unless constants such as EventArgs.Empty, String.Empty and so on.
|
|
|
|