[verb (dictionary form)] + ともなく + [same verb] [verb (dictionary form)] + ともなしに + [same verb] [question word] + (から / へ) + ともなく
ともなく puts the dictionary form of a verb before it and the same verb after it, and says you did it without meaning to or without paying attention: "idly", "half-", "without really". ともなしに means the same.
The verbs are mostly ones of seeing, hearing and thinking: みる見る, きく聞く, かんがえる考える, まつ待つ. With a question word as the object, the verb need not repeat, and the meaning becomes "not doing anything in particular".
ともなく belongs to novels and essays. In conversation, なんとなく or ぼんやり covers the first use: なんとなくてれびテレビをみていた見ていた.