|
The program is at initial stage. What i am looking is the method of file creation at specific time in c sharp, not using batch file or task scheduler as the program would be running at client PC. Would thankful if some one can share the logic to build the same in code.
|
|
|
|
|
There are many ways (and for some you wouldn't even have to use a c# program)
Solution 1
No need for C#. Create a batch file that you run daily at that specified time using the Task Scheduler. (Windows 7 explanation[^], but something like that exists in basically every OS)
Requirements: The OS has to be running during that time.
Batch-File :
copy /y NUL YourFileName.txt > NUL
Or just write some text into the file. It doesn't actually matter what you write inside your batch script. The Task Scheduler will just execute it.
Solution 2
Again, use the Task Scheduler. Just write your application in c# that outputs something to your text file.
Requirements: The OS has to be running during that time.
Solution 3
Write an Application that is always running. Implement a Timer that periodically checks what time it is. You'll probably need to check if you have already written the file for that day and reset it when you're rolling over to the next day.
Requirements: The OS and your application have to be running during that time.
There are probably many other possibilities depending on what exactly you're trying to do.
Without any information about what you're trying to do, it's basically impossible to recommend you anything. You may get a few ideas from this or you could provide some further details.
|
|
|
|
|
Thanks Nicholas for the possible way of achieving. What i am looking is to create a c# program which would be running at client PC and would be replicating the source file with destination. Currently the program is not completed and is looking for the sample logic where file would be created at destination folder at specific time say 00:30 am every day. If you refer the code, i am trying to use file system watcher for the replication. How to use below in file creation at the specified time.
File.SetCreationTime("dpath", new DateTime(2014, 4, 3));
How to define time in DateTime(2014, 4, 3) function. What would be the logic code ?
|
|
|
|
|
OK, so what's the problem?
|
|
|
|
|
Im currently stuck on a part of my assignment that i can't seem to figure out. It involves me setting up a game board, using a tablelayoutpanel as the gameboard.
So far, I have displayed the tile "Squares" on the board, but the tiles (cells) are not in order as so:
http://i.stack.imgur.com/vHYz7.png [1]
I need the start tile to be displayed in the bottom left, and the finish to be in the top right, with the cells in the middle in order as so:
http://i.stack.imgur.com/dcdy8.png [2]
The methods which pertain to this part are these:
private void SetupGameBoard() {
for (int i = 0; i <= 41; i++) {
SquareControl squareCreate = new SquareControl(Board.Squares[i], null);
int coloumn = 0;
int row = 0;
MapSquareNumToScreenRowAndColumn(i, out coloumn, out row);
boardTableLayoutPanel.Controls.Add(squareCreate, coloumn, row);
}
}
And this,
private static void MapSquareNumToScreenRowAndColumn(int squareNumber, out int rowNumber, out int columnNumber) {
rowNumber = 0;
columnNumber = 0;
}
What I've grasped so far is that in MapSquareToScreenRowandcColumn is where my calculation of figuring out where the squares fall into place needs to happen.
Would really love some tips/advice/help/anything on this.
If you guys need more info, let me know.
Thanks!
EDIT:
So I've figured out sort of how to do, just wondering about a better way to do it. In MapSqauretoScreenRowandColumn I put this little if statement just to test:
<pre lang="c#"> if (squareNumber >= 0 && squareNumber <= 5) {
rowNumber = 6;
}
So if the sqaurenumber is more than 0 and less than 5, its placed in the right row. My question is, is there a better way to do this for the rest? instead of writing a bunch of lines for this, is there are way to do it in a few?
EDIT2: Also, just a note, the top left of the board is (0,0) and the bottom right is (6,5)
|
|
|
|
|
Why do you not make it simpler and have a loop that goes through the rows, with an inner loop that goes through the columns. Something like:
for (int row = 0; row < MAXROWS; ++row)
{
for (int column = 0; column < MAXCOLUMNS; ++column)
{
}
}
|
|
|
|
|
Thanks for the reply. This is an exercise for my firt Uni c# programming class, so I'm fairly new to this.
Could you elaborate the comment section some more please?
I don't think I'm meant to calculate the number of pixels and such, since these squares are being placed inside tabellayoutpanel cells.
thanks again for the reply
|
|
|
|
|
You are correct you do not need to calculate pixel size. As to the rest it's a fairly simple issue of mathemtaics rather than programming. You have two loops, one for rows and one for columns. Within the columns loop you do whatever is necessary to position a square on the board, and given the row and column number you can make decisions as to what should be in each square. Rather than trying to work out the C# coding for this you should do some drawings on paper and think about what information you need at each point.
|
|
|
|
|
Thank a lot for the reply! I think I have some grasp of it now, but am having some trouble visualising it. I asked a friend for some advice, according to him,
Quote: the trick to getting it to work is dividing the square numbers in even rows by 6 and the remainder is the column number of that square number, then for the odd row's you just get the remainder of them but depending on what the remainder is, will determine what column they are, like if(squarenum % 6 == 0) then column is 5
and to find the row numbers you just use division by 6 aswell, like each 6 times you go through the loop go up(or down) a row
I think I understand what I have to do, just not really sure how. For example, how can I find the "even rows".
Funny thing is, I love puzzles like this, but this just has me completly stumped!
Again, thanks a lot for the replies guys.
EDIT:
OKAY! so I decided just to do it the long way, but I really want to know if there is a way to do it in less code. Here is my solution, any/all input would be very much appreciated!
private static void MapSquareNumToScreenRowAndColumn(int squareNumber, out int rowNumber, out int columnNumber){
rowNumber = 0;
columnNumber = 0;
columnNumber = squareNumber % 6;
rowNumber = squareNumber/6;
int remainder = squareNumber%6;
switch (remainder){
case 0:
columnNumber = 5;
break;
case 1:
columnNumber = 4;
break;
case 2:
columnNumber = 3;
break;
case 3:
columnNumber = 2;
break;
case 4:
columnNumber = 1;
break;
case 5:
columnNumber = 0;
break;
}
if (squareNumber >=0 && squareNumber <= 5){
rowNumber = 6;
columnNumber = squareNumber%6;
}
if (squareNumber >=6 && squareNumber <= 11){
rowNumber = 5;
}
if (squareNumber >=12 && squareNumber <= 17){
rowNumber = 4;
columnNumber = squareNumber%6;
}
if (squareNumber >=18 && squareNumber <= 23){
rowNumber = 3;
}
if (squareNumber >= 24 && squareNumber <= 29){
rowNumber = 2;
columnNumber = squareNumber%6;
}
if (squareNumber >= 30 && squareNumber <= 35){
rowNumber = 1;
}
if (squareNumber >= 36 && squareNumber <= 41){
rowNumber = 0;
columnNumber = squareNumber % 6;
}
}
modified 18-Oct-14 0:55am.
|
|
|
|
|
Why are you making it so complicated? For example why code that switch statement above, rather than the statements:
int remainder = squareNumber % 6;
columnNumber = 5 - remainder;
and something similar for the rows.
However I still think you would be better with the two loops I suggested, which always give you both row and column. If you want to add the left-to-right, right-to-left feature then you just need to enhance it slightly with something like this:
for (int row = MAXROWS; row >= 0 ; --row)
{
for (int column = 0; column < MAXCOLUMNS; ++column)
{
if (row & 1)
column = 5 - column;
}
}
|
|
|
|
|
I think I know what you are saying, but I am unsure whether that would works since my calculation for columnumer and rownumber has to takeplace in the second method mentioned in the OP. Since the first the method is calling the second method in a loop, wouldn't this cause the calculation in the second method to not work?
I've have been thinking, maybe I can use LINQ for this? Though I am very unsure how to use LINQ maybe its worth thinking about?
|
|
|
|
|
The calculation I have given you is all you need. Inside the second loop you have the values for row and column so you can access the exact location required.
|
|
|
|
|
Member 11160467 wrote: how can I find the "even rows" By studying the code in my reply here
« There is only one difference between a madman and me. The madman thinks he is sane. I know I am mad. » Salvador Dali
|
|
|
|
|
Richard MacCutchan wrote: In this case the OP is using a TableLayoutPanel where the position of his graphic-whatever is specified by row,column number, and their size is a factor in the layout design of the TLP ... although of course he could be setting row-height, and column-width in code for all we can tell from the post, I'd guess he's creating the layout of the TLP at design-time.
The interesting part is the alternate switching of cell order from left-to-right to right-to-left per row.
« There is only one difference between a madman and me. The madman thinks he is sane. I know I am mad. » Salvador Dali
|
|
|
|
|
You are correct, I was thinking in more general terms of the way to approach the problem. What is done in the inner loop is something the OP needs to think about; it is a University assignment after all.
|
|
|
|
|
Hi Richard, I am familiar with the OP through their previous posts on QA: imho, this is one person who is genuinely interested in learning, and working hard at it, struggling to do as much as possible on their own.
« There is only one difference between a madman and me. The madman thinks he is sane. I know I am mad. » Salvador Dali
|
|
|
|
|
I got that impression from the original question, and I did try to make my response helpful.
|
|
|
|
|
I'm going to post some code "hints" here for how you can implement the alternate-row ascending/descending order labeling of the Cells, but I'd like to see you answer the following questions:
What causes the apparently random order in which Cells are placed in the TableLayoutPanel in the first picture: your code ?
I was under the impression that you wanted the game to start with the Cells in random order: is that incorrect ? If you need to restore the cell order shown in your second picture frequently, you may choose to create a "mapping" in advance of cell-content to cell-location, rather than map by computation each time you need that order re-created. For example (deliberately incomplete sketch):
Dictionary<Point, string> cellMap = new Dictionary<Point, string>
{
{new Point(0,6), "Start"},
{new Point(5,0), "Final"},
{new Point(0,0), "36"},
{new Point(1,6), "1"},
};
private void ResetLayout()
{
YourTableLayoutPanel.Controls.Clear();
foreach (KeyValuePair<Point, string> kvp in cellMap)
{
Label lbl = new Label();
lbl.AutoSize = false;
lbl.Margin = new Padding(8);
lbl.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
lbl.TextAlign = ContentAlignment.MiddleRight;
lbl.Text = kvp.Value;
YourTableLayoutPanel.Controls.Add(lbl, kvp.Key.X, kvp.Key.Y);
}
} If you wish to create this layout by computation, then (deliberately incomplete example):
List<Label> lblList = new List<Label>();
private void orderLabels()
{
int count = 0;
Label cellLabel;
for (int row = 0; row < 7; row++)
{
for (int col = 0; col < 6; col++)
{
cellLabel = lblList[count];
if (count == 5)
{
cellLabel.Text = "Final";
YourTableLayoutPanel.Controls.Add(cellLabel, 5, 0);
}
else if (count == 36)
{
cellLabel.Text = "Start";
}
else
{
int offset;
if (row%2 == 0)
{
offset = (6 - row)*6 + col;
}
else
{
}
cellLabel.Text = offset.ToString();
YourTableLayoutPanel.Controls.Add(cellLabel, col, row);
}
count++;
}
}
} Of course, there are other ways you can approach re-creating this initial state. If I were writing a game, I think I'd want to implement a general mechanism for saving and restoring the state of any game configuration; I'd probably create a "game-state" Class and serialize/de-serialize that to save/restore configuration.
« There is only one difference between a madman and me. The madman thinks he is sane. I know I am mad. » Salvador Dali
modified 17-Oct-14 8:42am.
|
|
|
|
|
Hi,
I am looking for a solution to below requirement.
- Play/pause/Stop media through ASIO driver.
- Flexibility to perform above operations at specified channels.
- Flexibility to Play/Pause/Stop media at specified channels without affecting other channel.
I am able to achieve first 2 requirement through NAudio library. However, third and most important is not possible through NAudio as mentioned in the link http://stackoverflow.com/questions/14989516/multichannel-player-for-mono-channels/15006743#15006743[^]
I am using Dante Virtual Soundcard(DVS) for ASIO driver.
Questions:
1- Is it possible to control the channels individually in a ASIO driver ?
2- I have been looking at alternate options(DawnAudio, Bass.net) and didn't have success with the 3rd requirement. Is there any other C# library available to achieve 3rd requirement ?
I already posted a message few days back, however that was specific to NAudio and through this message, I am looking for a solution using any library(Free/Paid).
Appreciate any help on this.
|
|
|
|
|
Would PortAudio[^] fit the bill? (Haven't looked at it much yet)
There is a C# Wrapper[^] available. It says alpha, but I haven't found many bugs with my limited testing. There is another wrapper here[^] that may be of use as well.
I can create MSVC 9/10/11/12 builds of PortAudio and compiled versions of the wrappers if you would like me to. (The 9/10 builds might take a while as I am running those versions on a VM)
What do you get when you cross a joke with a rhetorical question?
---
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
|
|
|
|
|
Thanks for the response!
I'll have a look at them.
|
|
|
|
|
I was reading Marc Clifton's "Succinctly" book, "Imperative to Functional Programming" (published by SyncFusion, free download here: [^]), when I came across this interesting C# example on page #14:
static int EvenOrZero(int x)
{
return x % 2 == 0 ? x : 0;
}
int[] numbers = { 1, 2, 3, 4, 5 };
int sumOfEvenNumbers = numbers.Sum((Func<int, int>)EvenOrZero); Of course, Marc's code works. What intrigued me was the cast of the Function to Func<int,int>> about which Marc comments: "In this example, the cast is necessary to resolve the ambiguity between Func<int, int> and Func<int, int?>"
Since the 'Sum method has an overload which use only int, and not int?: Enumerable.Sum<TSource>> Method (IEnumerable<TSource>, Func<TSource, Int32>), I thought I could do something like this to avoid the cast:
private int EvenOrZero(int x)
{
return x % 2 == 0 ? x : 0;
}
List<int> numbers = new List<int>{ 1, 2, 3, 4, 5 };
int sumOfEvenNumbers = numbers.Sum<int>(EvenOrZero); Intellisense flags this with "Ambiguous invocation," and compiling this produces 3 errors:
Error 3 Cannot implicitly convert type 'decimal' to 'int'. An explicit conversion exists (are you missing a cast?)
Error 4 The call is ambiguous between the following methods or properties: 'System.Linq.Enumerable.Sum<int>(System.Collections.Generic.IEnumerable<int>, System.Func<int,decimal>)' and 'System.Linq.Enumerable.Sum<int>(System.Collections.Generic.IEnumerable<int>, System.Func<int,decimal?>)'
Error 5 'int ...EvenOrZero(int)' has the wrong return type Looking up the MS Doc for this overload of 'Sum [^] leads to an example that does not use int, but uses double !
What gives here with the required cast ? I assume that somehow the direct use of a named method in this case does not satisfy the compiler, but I have used named methods as the value of functions before with no problem.
« There is only one difference between a madman and me. The madman thinks he is sane. I know I am mad. » Salvador Dali
modified 16-Oct-14 18:09pm.
|
|
|
|
|
int sumOfEvenNumbers = numbers.Sum( x => EvenOrZero( x ) );
|
|
|
|
|
Down vote countered.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Eric Lippert posted an explanation of this on Stack Overflow:
Specifically, the subtle difference is that a method group is considered to be convertible to a delegate type solely on the basis of whether the arguments match, not also on the basis of whether the return type matches.
...
The upshot of it here is that your method group is convertible to all the different delegate types that are the second arguments of every version of Sum that takes a delegate. Since no best conversion can be found, the overload resolution on method group Sum is ambiguous.
He also has a blog post[^] talking about this in C# 3.
.NET 4.0 is a lot better at overload resolution for method groups, but this is one case where it still doesn't work.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|