|
In short the answer is no - multi threading is not the same as parallel processing.
One thing to bear in mind is if you do decide to dive into parallel processing what is your strategy for conflicts when two processes need to update the same data at the same time?
Probably the simplest and cheapest method is to up the RAM, on the computer running this application, and index any tables that are used in any background databases.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
On a single core machine I would agree with you, but those are not common these days. Threading done correctly is parallel programming and there are very easy ways to deal with resource contention. Many .NET BCL collections are atomic (thread safe), he could just store the results in there while running multiple threads and update the UI based on one way bindings.
Even the .NET TPL runs on a single machine, maybe you are thinking of distributed processing? He doesn't say that this is a RAM intensive or database application, its a network one that takes some time to gather information about network resources so I'm a little confused about your comment on RAM or database operations...
|
|
|
|
|
I read that he is using a datagrid and this led me to believe that may be using a database to populate the datagrid.
He doesn't state what the source of the datagrid is, only the contents.
He then mentions that he need to run two processes in parallel I understood that he wants to literally run two processes at the same time(that's what parallel means to me) - based on my understanding of threading this is not guaranteed by threading processes.
Hence my suggestion for more RAM to which could speed up bottlenecks in processing time and indexes based on my assumption with regards to the datagrid.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
Ooh, I just refreshed myself on looked at this .NET TPL[^] I stand corrected regarding threading...
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
If the operation he were conducting were processor/memory intensive I would agree that threading may not solve his issue, but with network operations most of the time is spent with the socket in a wait state (sending or receiving), which frees up more threads to get into the wait state or do other work. Since data may arrive from a thread started later than an earlier one, threading and tasks really do behave as if they operate in parallel, even on a single core processor.
The TPL was a major change to the .NET framework, which is why .NET 4 is an entire new runtime than 3/3.5 which runs on/are extensions to the 2.0 runtime.
|
|
|
|
|
<pre lang="text"> Hi there,
I am attempting to write a program which adds up the values in a 2D array to determine if the array is a magic square(that is, that all rows, all columns, and all diagonals add up to the same amount). As you can see I have not gotten very far, and am having trouble working out how to add up each separate row and store the values as separate variables , so I can compare them.
I would appretiate some help on this if possible.
private void RunQuestionFour()
{
int[,] anArray;
int columns;
int rows;
int tempTotalvalue = 0;
Random rndNumber1 = new Random();
Console.WriteLine("Please enter an integer to determine the size of the array e.g 5 = 5x5");
columns = Convert.ToInt16(Console.ReadLine());
rows = columns;
Console.WriteLine("\n");
anArray = new int[rows,columns];
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
int random1 = rndNumber1.Next(1, columns + 1);
anArray[i, j] = random1;
Console.Write("{0} ", anArray[i, j]);
}
Console.WriteLine();
}
for (int y = 0; y < rows; y++)
{
tempTotalvalue = 0;
for (int x = 0; x < columns; x++)
{
tempTotalvalue = tempTotalvalue + anArray[y, x];
}
Console.WriteLine(tempTotalvalue);
}
Console.ReadLine();
}
static void Main(string[] args)
{
Soft140 mySoft140 = new Soft140();
mySoft140.RunProgram();
Console.ReadKey();
}
}
}
|
|
|
|
|
|
It's not complicated: you don't need to store values, you just need to know if they are the same as each other.
So, start with moving your temporary value outside the rows loop:
int matchThis = -1;
for (int y = 0; y < rows; y++)
{
tempTotalvalue = 0;
for (int x = 0; x < columns; x++)
{
tempTotalvalue += anArray[y, x];
}
if (matchThis >= 0 && matchThis != tempTotalvalue)
{
Console.WriteLine("Not a magic square");
return;
}
matchThis = tempTotalvalue;
}
Console.WriteLine("Rows OK");
You can do much the same for the Columns (you can keep the existing value of matchThis - but the diagonals are slightly more of a problem! (There is a trick you can use though: look at the % operator - hint, hint)
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
You do realize that if you generate a #Nx#N matrix of random numbers the chance the result will satisfy the conditions for being a magic square are very low ... and, that as the size of the matrix increases, the chances get exponentially less and less ?
For validating whether your #Nx#N matrix is a magic square: traversing it using for-loops is quite straightforward, if tedious, but it's a good exercise to improve your mastery of for-loops to implement, I think. If you are new to C#, you might benefit from actually writing out the series of for-loop indexes you require for each test case (rows, columns, right-left diagonal, left-right diagonal).
If you are studying Linq and switch to using something like a List<List<int>> to hold your matrix, then Linq's operators like 'Sum can make validation much easier.
private bool testMagic(List<List<int>> testSquare)
{
int firstRowSum = testSquare[0].Sum();
for (int i = 1; i < magicNSides; i++)
{
if (testSquare[i].Sum() != firstRowSum) return false;
}
return true;
} For testing the Rows using Linq it can be even simpler:
bool IsMagicRows = squareList.All(x => (x.Sum() == firstRowSum)); Whichever strategy you use, validation in this case, imho, is best done in a way where you do a series of tests, and stop testing the moment any one of them fails.
For example, if you calculate the sum of the items on the first row of your array (or in the first List<string> inside your List<List<int>>) then you can start testing the other rows and stop immediately if any row does not have a sum equal to the sum of the first row.
“But I don't want to go among mad people,” Alice remarked.
“Oh, you can't help that,” said the Cat: “we're all mad here. I'm mad. You're mad.”
“How do you know I'm mad?” said Alice.
“You must be," said the Cat, or you wouldn't have come here.” Lewis Carroll
modified 20-Jan-14 15:24pm.
|
|
|
|
|
Hello, I have created a class to read an xml file, which contains 5 different list of tables. Therefore I have 5 different custom lists
List<listtables1>, List<listtables2> etc..
I would like to create a function to process any one of the 5 lists based on the user type.
Any ideas what is the best way to achieve this, instead of creating 5 different functions?
private void ProcessTableList()
{
// Need to declare a variable of type depending on user type
e.g. List<listtables1> customList = new List<listtables1>
for(int i=0; customList.countl i++)
{
//do something
}
}
.
modified 20-Jan-14 9:23am.
|
|
|
|
|
Sounds to me you'd want to use a Generic Method[^].
Cheers!
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
|
|
|
|
|
This is ASP.NET ? or Win Forms ? or ... ?
What are the underlying Types of the Tables; are they DataSets ?
“But I don't want to go among mad people,” Alice remarked.
“Oh, you can't help that,” said the Cat: “we're all mad here. I'm mad. You're mad.”
“How do you know I'm mad?” said Alice.
“You must be," said the Cat, or you wouldn't have come here.” Lewis Carroll
|
|
|
|
|
Depending on what the lists contain (any common data members) and what you need to do to them, you might consider using a common base class or an interface. You would then have 5 lists of that base class or interface and pass each one to the same function. As long as you only need to execute common functionality for all lists it should work.
If you need special functionality for some ofthe lists, you could either insert an if like
if (item is listtables1)
{
listtables1 tmp = (listtables1) item;
}
into the common function.
Or you use a different approach: You keep the lists of the special types and create a special function for each type that needs special handling. Then you can call the common function from the special functions passing the base class/interface of the current item. Or you call the common function directly in a loop for the classes without special handling.
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
Dear All,
i m new to VS2010, but i know some basic ,
my requirement is to connect oracle database using C#,
and i m able to do that,
i m want to do using with 3/4 tier archi.
just i know the connection string and database connectivity.
how to make my DAL class for oracle ...
any example would be appreciated
|
|
|
|
|
My advise would be to create a new project as class library. This will be your DAL component.
Then you need to build it with some things in mind:
* You want reusability. I created an interface and inhereted for different providers (mysql, oracle, odbc connectors etc...)
* You need some operations that are able to perform select, update, ... etc. But maybe also less convenient queries (Create table, alter table, ...) Personally I create ExecuteSelect, ExecuteUpdate, ... that takes a string (the sql) and another set ExecuteSelectSafe, ExecuteUpdateSafe, ... that takes the SQL and a list of parameternames and objectvalues.
* I included support for transactions
* I created a class that holds the result. eg the ExecuteXXX class returns that result which holds: a status (OK, FAILED, ...), an exception (if status is failed), the SQL query itself, A dataset, ... etc...
Note that for some providers you'll need the dll.
When built you can or strong-name it and install to the GAC or just reference the dll in any project you want to use it. Don't be lazy on this one, because it will become your bottleneck.
This is the Interface I wrote... Don't blindly copy/paste it. Start from scratch and try to understand what you're doing. (Note: this is an older version, I actually changed the "ENUM return values" into returning a result object containing the status, exception, dataset, ...
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Text;
namespace Framework.Dal
{
public static class DBResult
{
public enum DB_STATUS
{
UNDEFINED = 0,
CONNECTION_FAILED = 1,
CONNECTION_OK = 2,
EXECUTE_FAILED = 3,
EXECUTE_OK = 4,
}
}
public interface IDataBaseConnector
{
void SetConnection_String(string connection_string);
bool TestConnection();
DBResult.DB_STATUS ExecuteSelect(string stmnt);
DBResult.DB_STATUS ExecuteSelectSafe(string command, string[] paramnames, object[] paramvals);
DBResult.DB_STATUS ExecuteUpdate(string stmnt);
DBResult.DB_STATUS ExecuteUpdateSafe(string command, string[] paramnames, object[] paramvals);
DBResult.DB_STATUS ExecuteInsert(string stmnt);
DBResult.DB_STATUS ExecuteInsertSafe(string command, string [] paramnames, object [] paramvals);
DBResult.DB_STATUS ExecuteDelete(string stmnt);
DBResult.DB_STATUS ExecuteDeleteSafe(string command, string[] paramnames, object[] paramvals);
DBResult.DB_STATUS ExecuteStoredProcedure(string sp_name, ArrayList param_names, ArrayList param_values);
DBResult.DB_STATUS ExecuteNonQuery(string stmnt);
DataSet GetDataSet();
string GetLastErrorMessage();
string[] GetTables();
DataColumnCollection GetColumnInformation(string tablename);
int GetNrOfRowsAffected();
}
}
hope this helps.
|
|
|
|
|
I was been working on multiple desktop app. and would like to Screen shot of a desktop using the handle of the specific desktop.. I was using the blow code, but this always makes the the screenshort of current desktop.. as the Handle of "MyNewDesktop" was not supplyed. could you please tell me how to make use of hdesk to capture the screen short of the "MyNewDesktop". The below code is of utility app which captures desk top
hwinsta = OpenWindowStation("WinSta0", false, WINDOWS_STATION_ACCESS_MASK.WINSTA_ALL_ACCESS);
hwinsta2 = SetProcessWindowStation(hwinsta);
hdesk = OpenDesktop("MyNewDesktop", 0, false, DESKTOP_ACCESS_MASK.GENERIC_ALL);
bool thset = SetThreadDesktop(hdesk);
EnumDelegate delEnumfunc = new EnumDelegate(EnumWindowsProc);
IntPtr DesktopWindow = GetDesktopWindow();
bool bSuccessful = EnumDesktopWindows(hdesk, delEnumfunc, DesktopWindow);
if (bSuccessful)
{
string filename = string.Format("ScreenCap-{0:yyyy-MM-dd_hh-mm-ss-tt}", DateTime.Now);
var bounds = Screen.GetBounds(Point.Empty);
using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
}
bitmap.Save(@"C:\" + filename + ".jpg", ImageFormat.Jpeg);
}
}
else
{
int nErrorCode = Marshal.GetLastWin32Error();
string strErrMsg = String.Format("EnumDesktopWindows failed with code {0}.", nErrorCode);
throw new Exception(strErrMsg);
}
thanks
|
|
|
|
|
Just to clarify, you are expecting to run a utility on YOUR machine and capture the image of someone else desktop?
I would think you would need to deploy your utility on the target desktop, have it take the screenshot and send it to your app.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
No, it is windowsstation.. on the same PC you will have different desktop ie.. you can created and access
|
|
|
|
|
EnumDelegate delEnumfunc = new EnumDelegate(EnumWindowsProc);
IntPtr DesktopWindow = GetDesktopWindow();
bool bSuccessful = EnumDesktopWindows(hdesk, delEnumfunc, DesktopWindow);
And? What does the delegate do?
var bounds = Screen.GetBounds(Point.Empty);
Well, that Screen is the main screen, isn't it?
|
|
|
|
|
Thanks for response, Yes screen is the main screen, But how to capture the Screenshort of it... pls suggest
|
|
|
|
|
Dear All,
I am on the beginning stage on C# development. Currently I am developing an Voucher based Accounting Software with following:
1- Visual Studio 2010
2- Programming Language: C#
3- Database: MySql 5
At present, Database structure is as follows:
1.accAccounts (For holding information about Chart of Accounts like Account Code, Name, Subsidiary or Detail, Opening Balance etc)
2.vMaster (For Vouhcer Master information, Like Voucher Number, Date, Voucher Type (i.e Payment/Receipt/Journal), Payee Name, Remarks, Debit Account, Credit Account, Amount)
3. vDetails (For Voucher Detail information, used for further allocation of Expenses/Assets uses AccCode, Debit Amount, Credit Amount)
4. TranPost (All transactions from vMaster and vDetails will be posted in this table)
The General idea is this: User create new Voucher, enter transactions for Payment/receipt/journal etc. Then save the voucher. After approval of supervisor, Voucher will post and all transactions were copied to TransPost, once posted vMaster and vDetails were restricted to further editing.
Ofcourse when data is available in TransPost table, generation of Trial Balance, Balance Sheet & Income Statement will be based upon it.
Now my Question is: Is this the correct approach for development of Accounting Software? I am mainly concern about Year end closing process. Should I use same vMaster/vDetails/TransPost tables for every Accounting period or should I create new tables for each period? Assuming 50-80k transactions per year. What is the recommended way? For accMaster I think it should be the global table for All accounting periods, if yes, then it needs also in Master/Detail structure for holding different Opening balances for each year.
As mentioned, I am a beginner and what I've learned so far is by 'learn-by-doing' approach and guidance of all experience programmers in the forums like this. So I am in need of guidance again.
Looking forward for suggestions from all Masters specially those who are in development of Accounting Softwares.
Thanks in advance
Ahmed
|
|
|
|
|
As a beginner taking on a project of this scope I think you are nuts. I'd look for a smaller more defined project (probably business based but not the underlying accounting system).
If you are serious then you need to talk to an accountant conversant with various accounting systems, then nail down the scope of what you want to attempt and start getting some specs together working with the accountant.
On the other hand if you are attempting to create a simplistic invoicing system then talk to an accountant AND the business user - your client.
If this is for a business you should consider buying an existing system and bolting on your customised front end.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks for your reply, I haven't take this project for business purpose. It's a practice project for my self. Once mastering the important areas, I will move on to more advance topics.
Your suggestion to consult with accountant is already followed, as I am an Accountant , and learning programming as an hobby.
As an accountant I can assure you we can only provide information about Accounting policies not how a programmer map it to business logic in application, hence I am here.
So back to my original question: What is the recommended way to design Tables to record accounting transactions? Is it same transactions table to records multiple financial year data or multiple Tables for multiple year.
Regards
Ahmed
|
|
|
|
|
I am not an accountant nor have I ever worked on any accounting software, but I have dealt with database applications a lot. Your suggested records per year of 50-80K will definitely not be an issue for a database table on platforms like MySQL or MSSQL or Oracle or the likes, unless you are running wide open queries such as (select * from table) without any filter or limitation on rows returned.
Database design can become complicated if you want a very efficient means of storing your data. You may look over your required data several times and see if there are relations to break out into separate tables as much as possible and use primary keys, foreign keys and joins to bring your data together. Such as your "year" you could create a table that contains a primary key, year identifier and other year associated data and then that primary key would be a foreign key in your transaction table to match those transactions to that year etc.
Hopefully that kind of makes some sense and helps in some way.
|
|
|
|
|
Trak4Net wrote: I am not an accountant nor have I ever worked on any accounting software, but I have dealt with database applications a lot. Your suggested records per year of 50-80K will definitely not be an issue for a database table on platforms like MySQL or MSSQL or Oracle or the likes, unless you are running wide open queries such as (select * from table) without any filter or limitation on rows returned.
Database design can become complicated if you want a very efficient means of storing your data. You may look over your required data several times and see if there are relations to break out into separate tables as much as possible and use primary keys, foreign keys and joins to bring your data together. Such as your "year" you could create a table that contains a primary key, year identifier and other year associated data and then that primary key would be a foreign key in your transaction table to match those transactions to that year etc.
Hopefully that kind of makes some sense and helps in some way.
Very nice guidelines, I will definitely follow them, thanks a lot.
|
|
|
|
|